Skip to contentSkip to conversation

Change in openvpn[master]: Clean up the big msglevel type confusion

Openvpn-devel In review flichtenheld (Code Review) 2 participants 19 messages Jul 24, 2025 – Sep 19, 2025 1 message not in the archive Page 1 of 2

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1753364704000.Id492cb774c6d022d06bb3cf5fec2a4bdd410e619@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email

to review the following change.

Change subject: Clean up the big msglevel type confusion
......................................................................

Clean up the big msglevel type confusion

msglevel was definitely unsigned as the first
argument to msg(), but many parts of the code
had it as signed. So this produced a LOT of
warnings when enabling -Wsign-conversion.

There is one exception in struct status_output
where -1 is a valid value in the API. Only
positive values are translated into standard
message levels.

Change-Id Id492cb774c6d022d06bb3cf5fec2a4bdd410e619

---
M src/openvpn/argv.c
M src/openvpn/argv.h
M src/openvpn/buffer.c
M src/openvpn/clinat.c
M src/openvpn/clinat.h
M src/openvpn/comp.c
M src/openvpn/comp.h
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/dco.c
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dns.c
M src/openvpn/dns.h
M src/openvpn/env_set.c
M src/openvpn/env_set.h
M src/openvpn/error.c
M src/openvpn/error.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/manage.h
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/packet_id.c
M src/openvpn/plugin.c
M src/openvpn/plugin.h
M src/openvpn/pool.c
M src/openvpn/pool.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/sig.c
M src/openvpn/sig.h
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/ssl_verify_backend.h
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/status.c
M src/openvpn/status.h
M src/openvpn/tun.c
M src/openvpn/tun.h
M tests/unit_tests/openvpn/mock_ssl_dependencies.c M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_tls_crypt.c M tests/unit_tests/openvpn/test_user_pass.c

59 files changed, 185 insertions(+), 185 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/1110/1

src/openvpn/argv.c +9 -9
index 95215c0..2db510c 100644
@@ -236,14 +236,14 @@
 /**
  *  Write the arguments stored in a struct argv via the msg() command.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write.
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write.
  */
 void
-argv_msg(const int msglev, const struct argv *a)
+argv_msg(const unsigned int msglevel, const struct argv *a)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s", argv_str(a, &gc, 0));
+    msg(msglevel, "%s", argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
@@ -251,16 +251,16 @@
  *  Similar to argv_msg() but prefixes the messages being written with a
  *  given string.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write
- *  @param prefix  Valid pointer to the prefix string
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write
+ *  @param prefix    Valid pointer to the prefix string
  *
  */
 void
-argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix)
+argv_msg_prefix(const unsigned int msglevel, const struct argv *a, const char *prefix)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s: %s", prefix, argv_str(a, &gc, 0));
+    msg(msglevel, "%s: %s", prefix, argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
src/openvpn/argv.h +2 -2
index 098a1cb..866b405 100644
@@ -47,9 +47,9 @@
 
 struct argv argv_insert_head(const struct argv *a, const char *head);
 
-void argv_msg(const int msglev, const struct argv *a);
+void argv_msg(const unsigned int msglevel, const struct argv *a);
 
-void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix);
+void argv_msg_prefix(const unsigned int msglevel, const struct argv *a, const char *prefix);
 
 void argv_parse_cmd(struct argv *a, const char *s);
 
src/openvpn/buffer.c +1 -1
index dd6044b..456f591 100644
@@ -1130,7 +1130,7 @@
 {
     if (buf && buf->len)
     {
-        int msglevel = D_ALIGN_DEBUG;
+        unsigned int msglevel = D_ALIGN_DEBUG;
         const unsigned int u = (unsigned int) BPTR(buf);
 
         if (u & (PAYLOAD_ALIGN-1))
src/openvpn/clinat.c +3 -3
index f040724..81af08c 100644
@@ -49,7 +49,7 @@
 }
 
 void
-print_client_nat_list(const struct client_nat_option_list *list, int msglevel)
+print_client_nat_list(const struct client_nat_option_list *list, unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     int i;
@@ -108,7 +108,7 @@
                               const char *network,
                               const char *netmask,
                               const char *foreign_network,
-                              int msglevel)
+                              unsigned int msglevel)
 {
     struct client_nat_entry e;
     bool ok;
@@ -166,7 +166,7 @@
 #endif
 
 static void
-print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const int msglevel)
+print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
 
src/openvpn/clinat.h +2 -2
index 334b3f2..c099857 100644
@@ -51,14 +51,14 @@
 
 void copy_client_nat_option_list(struct client_nat_option_list *dest, const struct client_nat_option_list *src);
 
-void print_client_nat_list(const struct client_nat_option_list *list, int msglevel);
+void print_client_nat_list(const struct client_nat_option_list *list, unsigned int msglevel);
 
 void add_client_nat_to_option_list(struct client_nat_option_list *dest,
                                    const char *type,
                                    const char *network,
                                    const char *netmask,
                                    const char *foreign_network,
-                                   int msglevel);
+                                   unsigned int msglevel);
 
 void client_nat_transform(const struct client_nat_option_list *list,
                           struct buffer *ipbuf,
src/openvpn/comp.c +1 -1
index b2aa07e..2e17af4 100644
@@ -160,7 +160,7 @@
 #endif /* USE_COMP */
 
 bool
-check_compression_settings_valid(struct compress_options *info, int msglevel)
+check_compression_settings_valid(struct compress_options *info, unsigned int msglevel)
 {
     /*
      * We also allow comp-stub-v2 here as it technically allows escaping of
src/openvpn/comp.h +1 -1
index ee9c16a..37f3be7 100644
@@ -91,7 +91,7 @@
  * in
  */
 bool
-check_compression_settings_valid(struct compress_options *info, int msglevel);
+check_compression_settings_valid(struct compress_options *info, unsigned int msglevel);
 
 #ifdef USE_COMP
 #include "buffer.h"
src/openvpn/crypto.c +1 -1
index 7564f82..91b5da04 100644
@@ -1650,7 +1650,7 @@
 }
 
 int
-ascii2keydirection(int msglevel, const char *str)
+ascii2keydirection(unsigned int msglevel, const char *str)
 {
     if (!str)
     {
src/openvpn/crypto.h +1 -1
index 345e7ce..cd32bb4 100644
@@ -627,7 +627,7 @@
 
 void must_have_n_keys(const char *filename, const char *option, const struct key2 *key2, int n);
 
-int ascii2keydirection(int msglevel, const char *str);
+int ascii2keydirection(unsigned int msglevel, const char *str);
 
 const char *keydirection2ascii(int kd, bool remote, bool humanreadable);
 
src/openvpn/dco.c +4 -4
index 98cbb72..6ce86a2 100644
@@ -239,7 +239,7 @@
 }
 
 static bool
-dco_check_option_ce(const struct connection_entry *ce, int msglevel, int mode)
+dco_check_option_ce(const struct connection_entry *ce, unsigned int msglevel, int mode)
 {
     if (ce->fragment)
     {
@@ -297,7 +297,7 @@
 }
 
 bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(unsigned int msglevel, const struct options *o)
 {
     /* check if no dev name was specified at all. In the case,
      * later logic will most likely stop OpenVPN, so no need to
@@ -433,7 +433,7 @@
 }
 
 bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(unsigned int msglevel, const struct options *o)
 {
     /* At this point the ciphers have already been normalised */
     if (o->enable_ncp_fallback
@@ -479,7 +479,7 @@
 }
 
 bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(unsigned int msglevel, const struct options *o)
 {
     if (!o->use_peer_id)
     {
src/openvpn/dco.h +8 -8
index f38316d..3dbf19c 100644
@@ -56,7 +56,7 @@
  * @param msglevel      level to print messages to
  * @return              true if ovpn-dco is available, false otherwise
  */
-bool dco_available(int msglevel);
+bool dco_available(unsigned int msglevel);
 
 
 /**
@@ -76,7 +76,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_option(int msglevel, const struct options *o);
+bool dco_check_option(unsigned int msglevel, const struct options *o);
 
 /**
  * Check whether the options struct has any further option that is not supported
@@ -88,7 +88,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_startup_option(int msglevel, const struct options *o);
+bool dco_check_startup_option(unsigned int msglevel, const struct options *o);
 
 /**
  * Check whether any of the options pushed by the server is not supported by
@@ -99,7 +99,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_pull_options(int msglevel, const struct options *o);
+bool dco_check_pull_options(unsigned int msglevel, const struct options *o);
 
 /**
  * Initialize the DCO context
@@ -267,7 +267,7 @@
 typedef void *dco_context_t;
 
 static inline bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     return false;
 }
@@ -279,19 +279,19 @@
 }
 
 static inline bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
src/openvpn/dco_freebsd.c +1 -1
index b8816c6..bcd10b7 100644
@@ -582,7 +582,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     struct if_clonereq ifcr;
     char *buf = NULL;
src/openvpn/dco_linux.c +2 -2
index 3652a49..43753a5 100644
@@ -76,7 +76,7 @@
  * @return ID on success, negative error code on error
  */
 static int
-resolve_ovpn_netlink_id(int msglevel)
+resolve_ovpn_netlink_id(unsigned int msglevel)
 {
     int ret;
     struct nl_sock *nl_sock = nl_socket_alloc();
@@ -1196,7 +1196,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0)
     {
src/openvpn/dco_win.c +1 -1
index 83db739..15f7237 100644
@@ -598,7 +598,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     /* try to open device by symbolic name */
     HANDLE h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE,
src/openvpn/dns.c +1 -1
index ea3d91b..271186e 100644
@@ -201,7 +201,7 @@
 }
 
 bool
-dns_options_verify(int msglevel, const struct dns_options *o)
+dns_options_verify(unsigned int msglevel, const struct dns_options *o)
 {
     const struct dns_server *server =
         o->servers ? o->servers : o->servers_prepull;
src/openvpn/dns.h +1 -1
index d33f64e..ee70ed8 100644
@@ -157,7 +157,7 @@
  * @param   o           Pointer to the DNS options to validate
  * @return              True if no error was found
  */
-bool dns_options_verify(int msglevel, const struct dns_options *o);
+bool dns_options_verify(unsigned int msglevel, const struct dns_options *o);
 
 /**
  * Makes a deep copy of the passed DNS options.
src/openvpn/env_set.c +1 -1
index f20ee8a..cbf7d8f 100644
@@ -210,7 +210,7 @@
 }
 
 void
-env_set_print(int msglevel, const struct env_set *es)
+env_set_print(unsigned int msglevel, const struct env_set *es)
 {
     if (check_debug_level(msglevel))
     {
src/openvpn/env_set.h +1 -1
index 52c5312..42ebff0 100644
@@ -89,7 +89,7 @@
 
 const char *env_set_get(const struct env_set *es, const char *name);
 
-void env_set_print(int msglevel, const struct env_set *es);
+void env_set_print(unsigned int msglevel, const struct env_set *es);
 
 /**
  * Write a struct env_set to a file. Each item on one line.
src/openvpn/error.c +2 -2
index 049cd92..170076a 100644
@@ -409,8 +409,8 @@
     bool ret = true;
     if (mute_cutoff > 0 && !(flags & M_NOMUTE))
     {
-        const int mute_level = DECODE_MUTE_LEVEL(flags);
-        if (mute_level > 0 && mute_level == mute_category)
+        const unsigned int mute_level = DECODE_MUTE_LEVEL(flags);
+        if (mute_level == mute_category)
         {
             if (mute_count == mute_cutoff)
             {
src/openvpn/error.h +14 -14
index e0a2730..7744ef8 100644
@@ -84,22 +84,22 @@
 
 /* msg() flags */
 
-#define M_DEBUG_LEVEL     (0x0F)         /* debug level mask */
+#define M_DEBUG_LEVEL     (0x0Fu)         /* debug level mask */
 
-#define M_FATAL           (1<<4)         /* exit program */
-#define M_NONFATAL        (1<<5)         /* non-fatal error */
-#define M_WARN            (1<<6)         /* call syslog with LOG_WARNING */
-#define M_DEBUG           (1<<7)
+#define M_FATAL           (1u<<4)         /* exit program */
+#define M_NONFATAL        (1u<<5)         /* non-fatal error */
+#define M_WARN            (1u<<6)         /* call syslog with LOG_WARNING */
+#define M_DEBUG           (1u<<7)
 
-#define M_ERRNO           (1<<8)         /* show errno description */
+#define M_ERRNO           (1u<<8)         /* show errno description */
 
-#define M_NOMUTE          (1<<11)        /* don't do mute processing */
-#define M_NOPREFIX        (1<<12)        /* don't show date/time prefix */
-#define M_USAGE_SMALL     (1<<13)        /* fatal options error, call usage_small */
-#define M_MSG_VIRT_OUT    (1<<14)        /* output message through msg_status_output callback */
-#define M_OPTERR          (1<<15)        /* print "Options error:" prefix */
-#define M_NOLF            (1<<16)        /* don't print new line */
-#define M_NOIPREFIX       (1<<17)        /* don't print instance prefix */
+#define M_NOMUTE          (1u<<11)        /* don't do mute processing */
+#define M_NOPREFIX        (1u<<12)        /* don't show date/time prefix */
+#define M_USAGE_SMALL     (1u<<13)        /* fatal options error, call usage_small */
+#define M_MSG_VIRT_OUT    (1u<<14)        /* output message through msg_status_output callback */
+#define M_OPTERR          (1u<<15)        /* print "Options error:" prefix */
+#define M_NOLF            (1u<<16)        /* don't print new line */
+#define M_NOIPREFIX       (1u<<17)        /* don't print instance prefix */
 
 /* flag combinations which are frequently used */
 #define M_ERR     (M_FATAL | M_ERRNO)
@@ -113,7 +113,7 @@
  * A mute level of 0 is always printed.
  */
 #define MUTE_LEVEL_SHIFT 24
-#define MUTE_LEVEL_MASK 0xFF
+#define MUTE_LEVEL_MASK 0xFFu
 
 #define ENCODE_MUTE_LEVEL(mute_level) (((mute_level) & MUTE_LEVEL_MASK) << MUTE_LEVEL_SHIFT)
 #define DECODE_MUTE_LEVEL(flags) (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEVEL_MASK)
src/openvpn/forward.c +2 -2
index dfc6708..aab195d 100644
@@ -379,7 +379,7 @@
 
 bool
 send_control_channel_string_dowork(struct tls_session *session,
-                                   const char *str, int msglevel)
+                                   const char *str, unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     bool stat;
@@ -407,7 +407,7 @@
 }
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, unsigned int msglevel)
 {
     if (c->c2.tls_multi)
     {
src/openvpn/forward.h +2 -2
index b3e424c..aaf47fe 100644
@@ -287,7 +287,7 @@
  * @param msglevel   - Message level to use for logging
  */
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel);
+send_control_channel_string(struct context *c, const char *str, unsigned int msglevel);
 
 /*
  * Send a string to remote over the TLS control channel.
@@ -307,7 +307,7 @@
 
 bool
 send_control_channel_string_dowork(struct tls_session *session,
-                                   const char *str, int msglevel);
+                                   const char *str, unsigned int msglevel);
 
 
 /**
src/openvpn/init.c +1 -1
index 77747a2..641d7ee 100644
@@ -4379,7 +4379,7 @@
 }
 
 void
-management_show_net_callback(void *arg, const int msglevel)
+management_show_net_callback(void *arg, const unsigned int msglevel)
 {
 #ifdef _WIN32
     show_routes(msglevel);
src/openvpn/init.h +1 -1
index 5c6b9c1..40d8d04 100644
@@ -125,7 +125,7 @@
 
 void close_management(void);
 
-void management_show_net_callback(void *arg, const int msglevel);
+void management_show_net_callback(void *arg, const unsigned int msglevel);
 
 #endif
 
src/openvpn/manage.h +1 -1
index e25a615..3b4c18c 100644
@@ -178,7 +178,7 @@
     unsigned int flags;
 
     void (*status) (void *arg, const int version, struct status_output *so);
-    void (*show_net) (void *arg, const int msglevel);
+    void (*show_net) (void *arg, const unsigned int msglevel);
     int (*kill_by_cn) (void *arg, const char *common_name);
     int (*kill_by_addr) (void *arg, const in_addr_t addr, const int port, const int proto);
     void (*delete_event) (void *arg, event_t event);
src/openvpn/multi.c +1 -1
index ec260a2..b84f663 100644
@@ -3419,7 +3419,7 @@
     }
     else
     {
-        int msglevel = D_DCO;
+        unsigned int msglevel = D_DCO;
         if (dco->dco_message_type == OVPN_CMD_DEL_PEER
             && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
         {
src/openvpn/options.c +32 -32

250 lines not on this page · raw message

src/openvpn/options.h +6 -6
index 4ba8e3d..78b0d7c 100644
@@ -797,7 +797,7 @@
 void parse_argv(struct options *options,
                 const int argc,
                 char *argv[],
-                const int msglevel,
+                const unsigned int msglevel,
                 const unsigned int permission_mask,
                 unsigned int *option_types_found,
                 struct env_set *es);
@@ -872,7 +872,7 @@
 
 void options_server_import(struct options *o,
                            const char *filename,
-                           int msglevel,
+                           unsigned int msglevel,
                            unsigned int permission_mask,
                            unsigned int *option_types_found,
                            struct env_set *es);
@@ -886,14 +886,14 @@
                const int n,
                const char *file,
                const int line_num,
-               int msglevel,
+               unsigned int msglevel,
                struct gc_arena *gc);
 
 /*
  * parse/print topology coding
  */
 
-int parse_topology(const char *str, const int msglevel);
+int parse_topology(const char *str, const unsigned int msglevel);
 
 const char *print_topology(const int topology);
 
@@ -907,13 +907,13 @@
 
 int auth_retry_get(void);
 
-bool auth_retry_set(const int msglevel, const char *option);
+bool auth_retry_set(const unsigned int msglevel, const char *option);
 
 const char *auth_retry_print(void);
 
 void options_string_import(struct options *options,
                            const char *config,
-                           const int msglevel,
+                           const unsigned int msglevel,
                            const unsigned int permission_mask,
                            unsigned int *option_types_found,
                            struct env_set *es);
src/openvpn/options_util.c +2 -2
index 80d0c08..cb2a59c 100644
@@ -116,7 +116,7 @@
 }
 
 int
-positive_atoi(const char *str, int msglevel)
+positive_atoi(const char *str, unsigned int msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -132,7 +132,7 @@
 }
 
 int
-atoi_warn(const char *str, int msglevel)
+atoi_warn(const char *str, unsigned int msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
src/openvpn/options_util.h +2 -2
index 2474e7f..2f0b29b 100644
@@ -41,13 +41,13 @@
  * integer number. Otherwise print a warning with msglevel and return 0
  */
 int
-positive_atoi(const char *str, int msglevel);
+positive_atoi(const char *str, unsigned int msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
  * integer number. Otherwise print a warning with msglevel and return 0
  */
 int
-atoi_warn(const char *str, int msglevel);
+atoi_warn(const char *str, unsigned int msglevel);
 
 #endif /* ifndef OPTIONS_UTIL_H_ */
src/openvpn/packet_id.c +3 -3
index 76a81c6..057fdbd 100644
@@ -54,7 +54,7 @@
 #define SEQ_EXPIRED ((time_t)1)
 
 #ifdef ENABLE_DEBUG
-static void packet_id_debug_print(int msglevel,
+static void packet_id_debug_print(unsigned int msglevel,
                                   const struct packet_id_rec *p,
                                   const struct packet_id_net *pin,
                                   const char *message,
@@ -63,7 +63,7 @@
 #endif /* ENABLE_DEBUG */
 
 static inline void
-packet_id_debug(int msglevel,
+packet_id_debug(unsigned int msglevel,
                 const struct packet_id_rec *p,
                 const struct packet_id_net *pin,
                 const char *message,
@@ -592,7 +592,7 @@
 #ifdef ENABLE_DEBUG
 
 static void
-packet_id_debug_print(int msglevel,
+packet_id_debug_print(unsigned int msglevel,
                       const struct packet_id_rec *p,
                       const struct packet_id_net *pin,
                       const char *message,
src/openvpn/plugin.c +4 -4
index bafa469..3aafccf 100644
@@ -51,7 +51,7 @@
 static struct plugin_common *static_plugin_common = NULL; /* GLOBAL */
 
 static void
-plugin_show_string_array(int msglevel, const char *name, const char *array[])
+plugin_show_string_array(unsigned int msglevel, const char *name, const char *array[])
 {
     int i;
     for (i = 0; array[i]; ++i)
@@ -64,7 +64,7 @@
 }
 
 static void
-plugin_show_args_env(int msglevel, const char *argv[], const char *envp[])
+plugin_show_args_env(unsigned int msglevel, const char *argv[], const char *envp[])
 {
     if (check_debug_level(msglevel))
     {
@@ -186,7 +186,7 @@
 
 #ifndef ENABLE_SMALL
 void
-plugin_option_list_print(const struct plugin_option_list *list, int msglevel)
+plugin_option_list_print(const struct plugin_option_list *list, unsigned int msglevel)
 {
     int i;
     struct gc_arena gc = gc_new();
@@ -1024,7 +1024,7 @@
 
 #ifdef ENABLE_DEBUG
 void
-plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr)
+plugin_return_print(const unsigned int msglevel, const char *prefix, const struct plugin_return *pr)
 {
     int i;
     msg(msglevel, "PLUGIN_RETURN_PRINT %s", prefix);
src/openvpn/plugin.h +2 -2
index 5e91c60..003fcbb 100644
@@ -110,7 +110,7 @@
                             struct gc_arena *gc);
 
 #ifndef ENABLE_SMALL
-void plugin_option_list_print(const struct plugin_option_list *list, int msglevel);
+void plugin_option_list_print(const struct plugin_option_list *list, unsigned int msglevel);
 
 #endif
 
@@ -144,7 +144,7 @@
 void plugin_return_free(struct plugin_return *pr);
 
 #ifdef ENABLE_DEBUG
-void plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr);
+void plugin_return_print(const unsigned int msglevel, const char *prefix, const struct plugin_return *pr);
 
 #endif
 
src/openvpn/pool.c +2 -2
index ced172c..c144c01 100644
@@ -118,7 +118,7 @@
  * Verify start/end range
  */
 bool
-ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end)
+ifconfig_pool_verify_range(const unsigned int msglevel, const in_addr_t start, const in_addr_t end)
 {
     struct gc_arena gc = gc_new();
     bool ret = true;
@@ -534,7 +534,7 @@
 }
 
 static void
-ifconfig_pool_msg(const struct ifconfig_pool *pool, int msglevel)
+ifconfig_pool_msg(const struct ifconfig_pool *pool, unsigned int msglevel)
 {
     struct status_output *so = status_open(NULL, 0, msglevel, NULL, 0);
     ASSERT(so);
src/openvpn/pool.h +1 -1
index 9c3905d..b47cff0 100644
@@ -79,7 +79,7 @@
 
 void ifconfig_pool_free(struct ifconfig_pool *pool);
 
-bool ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end);
+bool ifconfig_pool_verify_range(const unsigned int msglevel, const in_addr_t start, const in_addr_t end);
 
 ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local, in_addr_t *remote, struct in6_addr *remote_ipv6, const char *common_name);
 
src/openvpn/push.c +5 -5
index ad8fa3d7..34e5b7a 100644
@@ -378,7 +378,7 @@
  * @return true on success, false on failure.
  */
 static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
-                            int msglevel, const char *fmt, ...)
+                            unsigned int msglevel, const char *fmt, ...)
 #ifdef __GNUC__
 #if __USE_MINGW_ANSI_STDIO
 __attribute__ ((format(gnu_printf, 4, 5)))
@@ -852,7 +852,7 @@
 
 static void
 push_option_ex(struct gc_arena *gc, struct push_list *push_list,
-               const char *opt, bool enable, int msglevel)
+               const char *opt, bool enable, unsigned int msglevel)
 {
     if (!string_class(opt, CC_ANY, CC_COMMA))
     {
@@ -880,7 +880,7 @@
 }
 
 void
-push_option(struct options *o, const char *opt, int msglevel)
+push_option(struct options *o, const char *opt, unsigned int msglevel)
 {
     push_option_ex(&o->gc, &o->push_list, opt, true, msglevel);
 }
@@ -902,7 +902,7 @@
 }
 
 void
-push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc)
+push_options(struct options *o, char **p, unsigned int msglevel, struct gc_arena *gc)
 {
     const char **argv = make_extended_arg_array(p, false, gc);
     char *opt = print_argv(argv, gc, 0);
@@ -911,7 +911,7 @@
 
 static bool
 push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
-                int msglevel, const char *format, ...)
+                unsigned int msglevel, const char *format, ...)
 {
     va_list arglist;
     char tmp[256] = {0};
src/openvpn/push.h +2 -2
index 048b4c4..86074d2 100644
@@ -58,9 +58,9 @@
 
 void clone_push_list(struct options *o);
 
-void push_option(struct options *o, const char *opt, int msglevel);
+void push_option(struct options *o, const char *opt, unsigned int msglevel);
 
-void push_options(struct options *o, char **p, int msglevel,
+void push_options(struct options *o, char **p, unsigned int msglevel,
                   struct gc_arena *gc);
 
 void push_reset(struct options *o);
src/openvpn/route.c +4 -4
index 156262a..2b624ba 100644
@@ -1340,7 +1340,7 @@
 }
 
 void
-print_default_gateway(const int msglevel,
+print_default_gateway(const unsigned int msglevel,
                       const struct route_gateway_info *rgi,
                       const struct route_ipv6_gateway_info *rgi6)
 {
@@ -3314,18 +3314,18 @@
  * Show current routing table
  */
 void
-show_routes(int msglev)
+show_routes(unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
 
     const MIB_IPFORWARDTABLE *rt = get_windows_routing_table(&gc);
 
-    msg(msglev, "SYSTEM ROUTING TABLE");
+    msg(msglevel, "SYSTEM ROUTING TABLE");
     if (rt)
     {
         for (DWORD i = 0; i < rt->dwNumEntries; ++i)
         {
-            msg(msglev, "%s", format_route_entry(&rt->table[i], &gc));
+            msg(msglevel, "%s", format_route_entry(&rt->table[i], &gc));
         }
     }
     gc_free(&gc);
src/openvpn/route.h +2 -2
index f015a12..faae424 100644
@@ -356,7 +356,7 @@
                               const struct in6_addr *dest,
                               openvpn_net_ctx_t *ctx);
 
-void print_default_gateway(const int msglevel,
+void print_default_gateway(const unsigned int msglevel,
                            const struct route_gateway_info *rgi,
                            const struct route_ipv6_gateway_info *rgi6);
 
@@ -381,7 +381,7 @@
 
 #ifdef _WIN32
 
-void show_routes(int msglev);
+void show_routes(unsigned int msglevel);
 
 bool test_routes(const struct route_list *rl, const struct tuntap *tt);
 
src/openvpn/run_command.c +1 -1
index 8b5fa4f..a41b05322 100644
@@ -108,7 +108,7 @@
 
 #ifndef WIN32
 bool
-openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel)
+openvpn_waitpid_check(pid_t pid, const char *msg_prefix, unsigned int msglevel)
 {
     if (pid == 0)
     {
src/openvpn/run_command.h +1 -1
index e9a6fe1..5570065 100644
@@ -75,7 +75,7 @@
  */
 bool
 openvpn_waitpid_check(pid_t pid, const char *msg_prefix,
-                      int msglevel);
+                      unsigned int msglevel);
 
 #endif
 
src/openvpn/sig.c +1 -1
index 9334b10..d8b6954 100644
@@ -291,7 +291,7 @@
 }
 
 void
-print_signal(const struct signal_info *si, const char *title, int msglevel)
+print_signal(const struct signal_info *si, const char *title, unsigned int msglevel)
 {
     if (si)
     {
src/openvpn/sig.h +1 -1
index fe81af9..8c808f6 100644
@@ -67,7 +67,7 @@
 
 void restore_signal_state(void);
 
-void print_signal(const struct signal_info *si, const char *title, int msglevel);
+void print_signal(const struct signal_info *si, const char *title, unsigned int msglevel);
 
 void print_status(struct context *c, struct status_output *so);
 
src/openvpn/socket.c +6 -6
index 980d8b4..2f31aca 100644
@@ -81,7 +81,7 @@
 get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname,
                  void *network, unsigned int *netbits,
                  int resolve_retry_seconds, struct signal_info *sig_info,
-                 int msglevel)
+                 unsigned int msglevel)
 {
     char *endp, *sep, *var_host = NULL;
     struct addrinfo *ai = NULL;
@@ -224,7 +224,7 @@
 
 bool
 get_ipv6_addr(const char *hostname, struct in6_addr *network,
-              unsigned int *netbits, int msglevel)
+              unsigned int *netbits, unsigned int msglevel)
 {
     if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostname, network, netbits,
                          0, NULL, msglevel) < 0)
@@ -477,7 +477,7 @@
     struct addrinfo hints;
     int status;
     struct signal_info sigrec = {0};
-    int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
+    unsigned int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
     struct gc_arena gc = gc_new();
     const char *print_hostname;
     const char *print_servname;
@@ -541,7 +541,7 @@
         int resolve_retries = (flags & GETADDR_TRY_ONCE) ? 1 :
                               ((resolve_retry_seconds + 4)/ fail_wait_interval);
         const char *fmt;
-        int level = 0;
+        unsigned int level = 0;
 
         /* this is not a numeric IP, therefore force resolution using the
          * provided ai_family */
@@ -689,7 +689,7 @@
 done:
     if (sig_info && sig_info->signal_received)
     {
-        int level = 0;
+        unsigned int level = 0;
         if (flags & GETADDR_FATAL_ON_SIGNAL)
         {
             level = M_FATAL;
@@ -2059,7 +2059,7 @@
 linksock_print_addr(struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
-    const int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
+    const unsigned int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
 
     /* print local address */
     if (sock->bind_local)
src/openvpn/socket.h +1 -1
index 6d71e83..26a13d6 100644
@@ -545,7 +545,7 @@
  * Translate an IPv6 addr or hostname from string form to in6_addr
  */
 bool get_ipv6_addr(const char *hostname, struct in6_addr *network,
-                   unsigned int *netbits, int msglevel);
+                   unsigned int *netbits, unsigned int msglevel);
 
 int openvpn_getaddrinfo(unsigned int flags,
                         const char *hostname,
src/openvpn/ssl_verify_backend.h +1 -1
index eb80cc8..b4711a5 100644
@@ -195,7 +195,7 @@
  *
  */
 void x509_track_add(const struct x509_track **ll_head, const char *name,
-                    int msglevel, struct gc_arena *gc);
+                    unsigned int msglevel, struct gc_arena *gc);
 
 /*
  * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_mbedtls.c +1 -1
index 25ad09c..2db7b17 100644
@@ -358,7 +358,7 @@
 }
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel, struct gc_arena *gc)
+x509_track_add(const struct x509_track **ll_head, const char *name, unsigned int msglevel, struct gc_arena *gc)
 {
     struct x509_track *xt;
     ALLOC_OBJ_CLEAR_GC(xt, struct x509_track, gc);
src/openvpn/ssl_verify_openssl.c +1 -1
index 1546815..57a2570 100644
@@ -421,7 +421,7 @@
  */
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel, struct gc_arena *gc)
+x509_track_add(const struct x509_track **ll_head, const char *name, unsigned int msglevel, struct gc_arena *gc)
 {
     struct x509_track *xt;
     ALLOC_OBJ_CLEAR_GC(xt, struct x509_track, gc);
src/openvpn/status.c +2 -3
index 4b0e516..06bb916 100644
@@ -239,14 +239,13 @@
 
         if (so->msglevel >= 0 && !so->errors)
         {
-            msg(so->msglevel, "%s", buf);
+            msg((unsigned int)so->msglevel, "%s", buf);
         }
 
         if (so->fd >= 0 && !so->errors)
         {
-            int len;
             strcat(buf, "\n");
-            len = strlen(buf);
+            size_t len = strlen(buf);
             if (len > 0)
             {
                 if (write(so->fd, buf, len) != len)
src/openvpn/status.h +1 -0
index eaed22a..9cd9325 100644
@@ -53,6 +53,7 @@
 
     char *filename;
     int fd;
+    /* NB: -1 is used to indicate that output should only go to the file */
     int msglevel;
     const struct virtual_output *vout;
 
src/openvpn/tun.c +27 -27

145 lines not on this page · raw message

src/openvpn/tun.h +2 -2
index 5407e47..77c1d76 100644
@@ -449,9 +449,9 @@
                           int *count,
                           in_addr_t *netmask);
 
-void show_tap_win_adapters(int msglev, int warnlev);
+void show_tap_win_adapters(unsigned int msglevel, unsigned int warnlevel);
 
-void show_adapters(int msglev);
+void show_adapters(unsigned int msglevel);
 
 void tap_allow_nonadmin_access(const char *dev_node);
 
tests/unit_tests/openvpn/mock_ssl_dependencies.c +1 -1
index 5cfe8d0..c8612ab 100644
@@ -39,7 +39,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file,
-           const int line_num, int msglevel, struct gc_arena *gc)
+           const int line_num, unsigned int msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_argv.c +1 -1
index 33b3dec..eb232dd 100644
@@ -23,7 +23,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file,
-                  const int line_num, int msglevel, struct gc_arena *gc)
+                  const int line_num, unsigned int msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_misc.c +1 -1
index 0c604ff..3272f6b 100644
@@ -335,7 +335,7 @@
     assert_false(valid_integer("-2147483653", false));
 
 
-    int msglevel = D_LOW;
+    unsigned int msglevel = D_LOW;
     int saved_log_level = mock_get_debug_level();
     mock_set_debug_level(D_LOW);
 
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
index adad40b..052e910 100644
@@ -60,7 +60,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file,
-           const int line_num, int msglevel, struct gc_arena *gc)
+           const int line_num, unsigned int msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_pkt.c +1 -1
index ebffabe..5f741f6 100644
@@ -46,7 +46,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file,
-           const int line_num, int msglevel, struct gc_arena *gc)
+           const int line_num, unsigned int msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_tls_crypt.c +1 -1
index cc415c8..998e10d 100644
@@ -100,7 +100,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file,
-                  const int line_num, int msglevel, struct gc_arena *gc)
+                  const int line_num, unsigned int msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_user_pass.c +1 -1
index 400c0f4..bc9ba54 100644
@@ -77,7 +77,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file,
-           const int line_num, int msglevel, struct gc_arena *gc)
+           const int line_num, unsigned int msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email )

Change subject: Clean up the big msglevel type confusion
......................................................................

Patch Set 10:

This change is ready for review.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 10
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Fri, 12 Sep 2025 15:37:55 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email )

Change subject: Clean up the big msglevel type confusion
......................................................................

Patch Set 10: Code-Review-1

(1 comment)

Patchset:

PS10:
Would it be less noisy and less space-consuming to change the other users to always use "int" instead?

Also, it breaks tests :-(

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 10
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 14 Sep 2025 17:42:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

Hello cron2, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email

to look at the new patch set (#11).

The following approvals got outdated and were removed:
Code-Review-1 by cron2

Change subject: Clean up the big msglevel type confusion
......................................................................

Clean up the big msglevel type confusion

msglevel was definitely unsigned as the first
argument to msg(), but many parts of the code
had it as signed. So this produced a LOT of
warnings when enabling -Wsign-conversion.

There is one exception in struct status_output
where -1 is a valid value in the API. Only
positive values are translated into standard
message levels.

Change-Id Id492cb774c6d022d06bb3cf5fec2a4bdd410e619

---
M src/openvpn/argv.c
M src/openvpn/argv.h
M src/openvpn/buffer.c
M src/openvpn/clinat.c
M src/openvpn/clinat.h
M src/openvpn/comp.c
M src/openvpn/comp.h
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/dco.c
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dns.c
M src/openvpn/dns.h
M src/openvpn/env_set.c
M src/openvpn/env_set.h
M src/openvpn/error.c
M src/openvpn/error.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/manage.h
M src/openvpn/mtu.c
M src/openvpn/mtu.h
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/packet_id.c
M src/openvpn/plugin.c
M src/openvpn/plugin.h
M src/openvpn/pool.c
M src/openvpn/pool.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/sig.c
M src/openvpn/sig.h
M src/openvpn/socket.c
M src/openvpn/socket_util.c
M src/openvpn/socket_util.h
M src/openvpn/ssl_verify_backend.h
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/status.c
M src/openvpn/status.h
M src/openvpn/tun.c
M src/openvpn/tun.h
M tests/unit_tests/openvpn/mock_ssl_dependencies.c M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_push_update_msg.c M tests/unit_tests/openvpn/test_tls_crypt.c M tests/unit_tests/openvpn/test_user_pass.c

63 files changed, 232 insertions(+), 224 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/1110/11

src/openvpn/argv.c +9 -9
index 903fc0a..55deef5 100644
@@ -235,14 +235,14 @@
 /**
  *  Write the arguments stored in a struct argv via the msg() command.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write.
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write.
  */
 void
-argv_msg(const int msglev, const struct argv *a)
+argv_msg(const unsigned int msglevel, const struct argv *a)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s", argv_str(a, &gc, 0));
+    msg(msglevel, "%s", argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
@@ -250,16 +250,16 @@
  *  Similar to argv_msg() but prefixes the messages being written with a
  *  given string.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write
- *  @param prefix  Valid pointer to the prefix string
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write
+ *  @param prefix    Valid pointer to the prefix string
  *
  */
 void
-argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix)
+argv_msg_prefix(const unsigned int msglevel, const struct argv *a, const char *prefix)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s: %s", prefix, argv_str(a, &gc, 0));
+    msg(msglevel, "%s: %s", prefix, argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
src/openvpn/argv.h +2 -2
index 056fe31..724b827 100644
@@ -47,9 +47,9 @@
 
 struct argv argv_insert_head(const struct argv *a, const char *head);
 
-void argv_msg(const int msglev, const struct argv *a);
+void argv_msg(const unsigned int msglevel, const struct argv *a);
 
-void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix);
+void argv_msg_prefix(const unsigned int msglevel, const struct argv *a, const char *prefix);
 
 void argv_parse_cmd(struct argv *a, const char *s);
 
src/openvpn/buffer.c +1 -1
index 0f0d17e..b6d6669 100644
@@ -1127,7 +1127,7 @@
 {
     if (buf && buf->len)
     {
-        int msglevel = D_ALIGN_DEBUG;
+        unsigned int msglevel = D_ALIGN_DEBUG;
         const unsigned int u = (unsigned int)BPTR(buf);
 
         if (u & (PAYLOAD_ALIGN - 1))
src/openvpn/clinat.c +3 -3
index 48a2057..2d21daf 100644
@@ -47,7 +47,7 @@
 }
 
 void
-print_client_nat_list(const struct client_nat_option_list *list, int msglevel)
+print_client_nat_list(const struct client_nat_option_list *list, unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     int i;
@@ -101,7 +101,7 @@
 void
 add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                               const char *network, const char *netmask, const char *foreign_network,
-                              int msglevel)
+                              unsigned int msglevel)
 {
     struct client_nat_entry e;
     bool ok;
@@ -159,7 +159,7 @@
 #endif
 
 static void
-print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const int msglevel)
+print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
 
src/openvpn/clinat.h +2 -2
index abfa0b7..3fcdf70 100644
@@ -54,11 +54,11 @@
 void copy_client_nat_option_list(struct client_nat_option_list *dest,
                                  const struct client_nat_option_list *src);
 
-void print_client_nat_list(const struct client_nat_option_list *list, int msglevel);
+void print_client_nat_list(const struct client_nat_option_list *list, unsigned int msglevel);
 
 void add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                                    const char *network, const char *netmask,
-                                   const char *foreign_network, int msglevel);
+                                   const char *foreign_network, unsigned int msglevel);
 
 void client_nat_transform(const struct client_nat_option_list *list, struct buffer *ipbuf,
                           const int direction);
src/openvpn/comp.c +1 -1
index 1a2e775..305184d 100644
@@ -159,7 +159,7 @@
 #endif /* USE_COMP */
 
 bool
-check_compression_settings_valid(struct compress_options *info, int msglevel)
+check_compression_settings_valid(struct compress_options *info, unsigned int msglevel)
 {
     /*
      * We also allow comp-stub-v2 here as it technically allows escaping of
src/openvpn/comp.h +1 -1
index 0354896..5327eae 100644
@@ -89,7 +89,7 @@
  * flags of allow-compression and also the whether algorithms are compiled
  * in
  */
-bool check_compression_settings_valid(struct compress_options *info, int msglevel);
+bool check_compression_settings_valid(struct compress_options *info, unsigned int msglevel);
 
 #ifdef USE_COMP
 #include "buffer.h"
src/openvpn/crypto.c +1 -1
index 804d2ad..8e56881 100644
@@ -1618,7 +1618,7 @@
 }
 
 int
-ascii2keydirection(int msglevel, const char *str)
+ascii2keydirection(unsigned int msglevel, const char *str)
 {
     if (!str)
     {
src/openvpn/crypto.h +1 -1
index efd7f60..a403f32 100644
@@ -618,7 +618,7 @@
 
 void must_have_n_keys(const char *filename, const char *option, const struct key2 *key2, int n);
 
-int ascii2keydirection(int msglevel, const char *str);
+int ascii2keydirection(unsigned int msglevel, const char *str);
 
 const char *keydirection2ascii(int kd, bool remote, bool humanreadable);
 
src/openvpn/dco.c +4 -4
index fc45e67..be4c592 100644
@@ -233,7 +233,7 @@
 }
 
 static bool
-dco_check_option_ce(const struct connection_entry *ce, int msglevel, int mode)
+dco_check_option_ce(const struct connection_entry *ce, unsigned int msglevel, int mode)
 {
     if (ce->fragment)
     {
@@ -293,7 +293,7 @@
 }
 
 bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(unsigned int msglevel, const struct options *o)
 {
     /* check if no dev name was specified at all. In the case,
      * later logic will most likely stop OpenVPN, so no need to
@@ -430,7 +430,7 @@
 }
 
 bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(unsigned int msglevel, const struct options *o)
 {
     /* At this point the ciphers have already been normalised */
     if (o->enable_ncp_fallback
@@ -480,7 +480,7 @@
 }
 
 bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(unsigned int msglevel, const struct options *o)
 {
     if (!o->use_peer_id)
     {
src/openvpn/dco.h +8 -8
index 59acb18..7fa8055 100644
@@ -55,7 +55,7 @@
  * @param msglevel      level to print messages to
  * @return              true if ovpn-dco is available, false otherwise
  */
-bool dco_available(int msglevel);
+bool dco_available(unsigned int msglevel);
 
 
 /**
@@ -75,7 +75,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_option(int msglevel, const struct options *o);
+bool dco_check_option(unsigned int msglevel, const struct options *o);
 
 /**
  * Check whether the options struct has any further option that is not supported
@@ -87,7 +87,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_startup_option(int msglevel, const struct options *o);
+bool dco_check_startup_option(unsigned int msglevel, const struct options *o);
 
 /**
  * Check whether any of the options pushed by the server is not supported by
@@ -98,7 +98,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_pull_options(int msglevel, const struct options *o);
+bool dco_check_pull_options(unsigned int msglevel, const struct options *o);
 
 /**
  * Initialize the DCO context
@@ -261,7 +261,7 @@
 typedef void *dco_context_t;
 
 static inline bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     return false;
 }
@@ -273,19 +273,19 @@
 }
 
 static inline bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
src/openvpn/dco_freebsd.c +1 -1
index 0bdad14..32d17d1 100644
@@ -663,7 +663,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     struct if_clonereq ifcr;
     char *buf = NULL;
src/openvpn/dco_linux.c +2 -2
index 3b08f33..accd432 100644
@@ -79,7 +79,7 @@
  * @return ID on success, negative error code on error
  */
 static int
-resolve_ovpn_netlink_id(int msglevel)
+resolve_ovpn_netlink_id(unsigned int msglevel)
 {
     int ret;
     struct nl_sock *nl_sock = nl_socket_alloc();
@@ -1204,7 +1204,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0)
     {
src/openvpn/dco_win.c +1 -1
index 1dc5cf8..39a5ab6 100644
@@ -609,7 +609,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     /* try to open device by symbolic name */
     HANDLE h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
src/openvpn/dns.c +1 -1
index 8554089..1e8ce06 100644
@@ -200,7 +200,7 @@
 }
 
 bool
-dns_options_verify(int msglevel, const struct dns_options *o)
+dns_options_verify(unsigned int msglevel, const struct dns_options *o)
 {
     const struct dns_server *server = o->servers ? o->servers : o->servers_prepull;
     while (server)
src/openvpn/dns.h +1 -1
index 6d97b40..833b937 100644
@@ -166,7 +166,7 @@
  * @param   o           Pointer to the DNS options to validate
  * @return              True if no error was found
  */
-bool dns_options_verify(int msglevel, const struct dns_options *o);
+bool dns_options_verify(unsigned int msglevel, const struct dns_options *o);
 
 /**
  * Makes a deep copy of the passed DNS options.
src/openvpn/env_set.c +1 -1
index 6c7df8e..487a5e2 100644
@@ -209,7 +209,7 @@
 }
 
 void
-env_set_print(int msglevel, const struct env_set *es)
+env_set_print(unsigned int msglevel, const struct env_set *es)
 {
     if (check_debug_level(msglevel))
     {
src/openvpn/env_set.h +1 -1
index 3973a4e..130de75 100644
@@ -85,7 +85,7 @@
 
 const char *env_set_get(const struct env_set *es, const char *name);
 
-void env_set_print(int msglevel, const struct env_set *es);
+void env_set_print(unsigned int msglevel, const struct env_set *es);
 
 /**
  * Write a struct env_set to a file. Each item on one line.
src/openvpn/error.c +2 -2
index 1b98235..90c0f75 100644
@@ -390,8 +390,8 @@
     bool ret = true;
     if (mute_cutoff > 0 && !(flags & M_NOMUTE))
     {
-        const int mute_level = DECODE_MUTE_LEVEL(flags);
-        if (mute_level > 0 && mute_level == mute_category)
+        const unsigned int mute_level = DECODE_MUTE_LEVEL(flags);
+        if (mute_level == mute_category)
         {
             if (mute_count == mute_cutoff)
             {
src/openvpn/error.h +14 -14
index 8388f82..2ad2c5d 100644
@@ -83,22 +83,22 @@
 
 /* msg() flags */
 
-#define M_DEBUG_LEVEL (0x0F) /* debug level mask */
+#define M_DEBUG_LEVEL (0x0Fu) /* debug level mask */
 
-#define M_FATAL    (1 << 4)  /* exit program */
-#define M_NONFATAL (1 << 5)  /* non-fatal error */
-#define M_WARN     (1 << 6)  /* call syslog with LOG_WARNING */
-#define M_DEBUG    (1 << 7)
+#define M_FATAL    (1u << 4)  /* exit program */
+#define M_NONFATAL (1u << 5)  /* non-fatal error */
+#define M_WARN     (1u << 6)  /* call syslog with LOG_WARNING */
+#define M_DEBUG    (1u << 7)
 
-#define M_ERRNO (1 << 8)         /* show errno description */
+#define M_ERRNO (1u << 8)         /* show errno description */
 
-#define M_NOMUTE       (1 << 11) /* don't do mute processing */
-#define M_NOPREFIX     (1 << 12) /* don't show date/time prefix */
-#define M_USAGE_SMALL  (1 << 13) /* fatal options error, call usage_small */
-#define M_MSG_VIRT_OUT (1 << 14) /* output message through msg_status_output callback */
-#define M_OPTERR       (1 << 15) /* print "Options error:" prefix */
-#define M_NOLF         (1 << 16) /* don't print new line */
-#define M_NOIPREFIX    (1 << 17) /* don't print instance prefix */
+#define M_NOMUTE       (1u << 11) /* don't do mute processing */
+#define M_NOPREFIX     (1u << 12) /* don't show date/time prefix */
+#define M_USAGE_SMALL  (1u << 13) /* fatal options error, call usage_small */
+#define M_MSG_VIRT_OUT (1u << 14) /* output message through msg_status_output callback */
+#define M_OPTERR       (1u << 15) /* print "Options error:" prefix */
+#define M_NOLF         (1u << 16) /* don't print new line */
+#define M_NOIPREFIX    (1u << 17) /* don't print instance prefix */
 
 /* flag combinations which are frequently used */
 #define M_ERR    (M_FATAL | M_ERRNO)
@@ -112,7 +112,7 @@
  * A mute level of 0 is always printed.
  */
 #define MUTE_LEVEL_SHIFT 24
-#define MUTE_LEVEL_MASK  0xFF
+#define MUTE_LEVEL_MASK  0xFFu
 
 #define ENCODE_MUTE_LEVEL(mute_level) (((mute_level) & MUTE_LEVEL_MASK) << MUTE_LEVEL_SHIFT)
 #define DECODE_MUTE_LEVEL(flags)      (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEVEL_MASK)
src/openvpn/forward.c +3 -2
index 5dc244a..7e38e2c 100644
@@ -373,7 +373,8 @@
 #endif
 
 bool
-send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel)
+send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                   unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     bool stat;
@@ -400,7 +401,7 @@
 }
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, unsigned int msglevel)
 {
     if (c->c2.tls_multi)
     {
src/openvpn/forward.h +3 -2
index 79d0f8b..581eae1 100644
@@ -285,7 +285,7 @@
  * @param str        - The message to be sent
  * @param msglevel   - Message level to use for logging
  */
-bool send_control_channel_string(struct context *c, const char *str, int msglevel);
+bool send_control_channel_string(struct context *c, const char *str, unsigned int msglevel);
 
 /*
  * Send a string to remote over the TLS control channel.
@@ -303,7 +303,8 @@
  * @param msglevel   - Message level to use for logging
  */
 
-bool send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel);
+bool send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                        unsigned int msglevel);
 
 
 /**
src/openvpn/init.c +1 -1
index fcb3365..7a80619 100644
@@ -4282,7 +4282,7 @@
 }
 
 void
-management_show_net_callback(void *arg, const int msglevel)
+management_show_net_callback(void *arg, const unsigned int msglevel)
 {
 #ifdef _WIN32
     show_routes(msglevel);
src/openvpn/init.h +1 -1
index a807874..432cf31 100644
@@ -136,7 +136,7 @@
 
 void close_management(void);
 
-void management_show_net_callback(void *arg, const int msglevel);
+void management_show_net_callback(void *arg, const unsigned int msglevel);
 
 #endif
 
src/openvpn/manage.h +1 -1
index 0bce25e..6c78fe8 100644
@@ -176,7 +176,7 @@
     unsigned int flags;
 
     void (*status)(void *arg, const int version, struct status_output *so);
-    void (*show_net)(void *arg, const int msglevel);
+    void (*show_net)(void *arg, const unsigned int msglevel);
     int (*kill_by_cn)(void *arg, const char *common_name);
     int (*kill_by_addr)(void *arg, const in_addr_t addr, const int port, const int proto);
     void (*delete_event)(void *arg, event_t event);
src/openvpn/mtu.c +2 -2
index 1e021e3..f5bc814 100644
@@ -187,7 +187,7 @@
 }
 
 void
-frame_print(const struct frame *frame, int level, const char *prefix)
+frame_print(const struct frame *frame, unsigned int msglevel, const char *prefix)
 {
     struct gc_arena gc = gc_new();
     struct buffer out = alloc_buf_gc(256, &gc);
@@ -208,7 +208,7 @@
     buf_printf(&out, " ET:%d", frame->extra_tun);
     buf_printf(&out, " ]");
 
-    msg(level, "%s", out.data);
+    msg(msglevel, "%s", out.data);
     gc_free(&gc);
 }
 
src/openvpn/mtu.h +1 -1
index c092461..c555f51 100644
@@ -181,7 +181,7 @@
  * Function prototypes.
  */
 
-void frame_print(const struct frame *frame, int level, const char *prefix);
+void frame_print(const struct frame *frame, unsigned int msglevel, const char *prefix);
 
 void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af);
 
src/openvpn/multi.c +1 -1
index e3bc445..c33bb0a 100644
@@ -3319,7 +3319,7 @@
     }
     else
     {
-        int msglevel = D_DCO;
+        unsigned int msglevel = D_DCO;
         if (dco->dco_message_type == OVPN_CMD_DEL_PEER
             && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
         {
src/openvpn/options.c +52 -48

330 lines not on this page · raw message

src/openvpn/options.h +6 -6
index bb2c052..5e918bb 100644
@@ -822,7 +822,7 @@
     struct pull_filter *tail;
 };
 
-void parse_argv(struct options *options, const int argc, char *argv[], const int msglevel,
+void parse_argv(struct options *options, const int argc, char *argv[], const unsigned int msglevel,
                 const unsigned int permission_mask, unsigned int *option_types_found,
                 struct env_set *es);
 
@@ -888,7 +888,7 @@
 
 void options_detach(struct options *o);
 
-void options_server_import(struct options *o, const char *filename, int msglevel,
+void options_server_import(struct options *o, const char *filename, unsigned int msglevel,
                            unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
@@ -897,13 +897,13 @@
 void rol_check_alloc(struct options *options);
 
 int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num,
-               int msglevel, struct gc_arena *gc);
+               unsigned int msglevel, struct gc_arena *gc);
 
 /*
  * parse/print topology coding
  */
 
-int parse_topology(const char *str, const int msglevel);
+int parse_topology(const char *str, const unsigned int msglevel);
 
 const char *print_topology(const int topology);
 
@@ -917,11 +917,11 @@
 
 int auth_retry_get(void);
 
-bool auth_retry_set(const int msglevel, const char *option);
+bool auth_retry_set(const unsigned int msglevel, const char *option);
 
 const char *auth_retry_print(void);
 
-void options_string_import(struct options *options, const char *config, const int msglevel,
+void options_string_import(struct options *options, const char *config, const unsigned int msglevel,
                            const unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
src/openvpn/options_util.c +2 -2
index 0f81435..96ade23 100644
@@ -117,7 +117,7 @@
 }
 
 int
-positive_atoi(const char *str, int msglevel)
+positive_atoi(const char *str, unsigned int msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -132,7 +132,7 @@
 }
 
 int
-atoi_warn(const char *str, int msglevel)
+atoi_warn(const char *str, unsigned int msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
src/openvpn/options_util.h +2 -2
index 9eca7b6..59ffe60 100644
@@ -37,13 +37,13 @@
  * Converts a str to a positive number if the string represents a postive
  * integer number. Otherwise print a warning with msglevel and return 0
  */
-int positive_atoi(const char *str, int msglevel);
+int positive_atoi(const char *str, unsigned int msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
  * integer number. Otherwise print a warning with \p msglevel and return 0
  */
-int atoi_warn(const char *str, int msglevel);
+int atoi_warn(const char *str, unsigned int msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
src/openvpn/packet_id.c +5 -4
index 0b33c9c..63a4cae 100644
@@ -53,15 +53,15 @@
 #define SEQ_EXPIRED ((time_t)1)
 
 #ifdef ENABLE_DEBUG
-static void packet_id_debug_print(int msglevel, const struct packet_id_rec *p,
+static void packet_id_debug_print(unsigned int msglevel, const struct packet_id_rec *p,
                                   const struct packet_id_net *pin, const char *message,
                                   packet_id_print_type value);
 
 #endif /* ENABLE_DEBUG */
 
 static inline void
-packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
-                const char *message, uint64_t value)
+packet_id_debug(unsigned int msglevel, const struct packet_id_rec *p,
+                const struct packet_id_net *pin, const char *message, uint64_t value)
 {
 #ifdef ENABLE_DEBUG
     if (unlikely(check_debug_level(msglevel)))
@@ -578,7 +578,8 @@
 #ifdef ENABLE_DEBUG
 
 static void
-packet_id_debug_print(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
+packet_id_debug_print(unsigned int msglevel, const struct packet_id_rec *p,
+                      const struct packet_id_net *pin,
                       const char *message, packet_id_print_type value)
 {
     struct gc_arena gc = gc_new();
src/openvpn/plugin.c +4 -4
index e65a3bc..769fe65 100644
@@ -50,7 +50,7 @@
 static struct plugin_common *static_plugin_common = NULL; /* GLOBAL */
 
 static void
-plugin_show_string_array(int msglevel, const char *name, const char *array[])
+plugin_show_string_array(unsigned int msglevel, const char *name, const char *array[])
 {
     int i;
     for (i = 0; array[i]; ++i)
@@ -63,7 +63,7 @@
 }
 
 static void
-plugin_show_args_env(int msglevel, const char *argv[], const char *envp[])
+plugin_show_args_env(unsigned int msglevel, const char *argv[], const char *envp[])
 {
     if (check_debug_level(msglevel))
     {
@@ -184,7 +184,7 @@
 
 #ifndef ENABLE_SMALL
 void
-plugin_option_list_print(const struct plugin_option_list *list, int msglevel)
+plugin_option_list_print(const struct plugin_option_list *list, unsigned int msglevel)
 {
     int i;
     struct gc_arena gc = gc_new();
@@ -995,7 +995,7 @@
 
 #ifdef ENABLE_DEBUG
 void
-plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr)
+plugin_return_print(const unsigned int msglevel, const char *prefix, const struct plugin_return *pr)
 {
     int i;
     msg(msglevel, "PLUGIN_RETURN_PRINT %s", prefix);
src/openvpn/plugin.h +2 -2
index 63999b6..91d3fba 100644
@@ -111,7 +111,7 @@
 bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc);
 
 #ifndef ENABLE_SMALL
-void plugin_option_list_print(const struct plugin_option_list *list, int msglevel);
+void plugin_option_list_print(const struct plugin_option_list *list, unsigned int msglevel);
 
 #endif
 
@@ -136,7 +136,7 @@
 void plugin_return_free(struct plugin_return *pr);
 
 #ifdef ENABLE_DEBUG
-void plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr);
+void plugin_return_print(const unsigned int msglevel, const char *prefix, const struct plugin_return *pr);
 
 #endif
 
src/openvpn/pool.c +2 -2
index fde6cea..0e95c5e 100644
@@ -114,7 +114,7 @@
  * Verify start/end range
  */
 bool
-ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end)
+ifconfig_pool_verify_range(const unsigned int msglevel, const in_addr_t start, const in_addr_t end)
 {
     struct gc_arena gc = gc_new();
     bool ret = true;
@@ -521,7 +521,7 @@
 }
 
 static void
-ifconfig_pool_msg(const struct ifconfig_pool *pool, int msglevel)
+ifconfig_pool_msg(const struct ifconfig_pool *pool, unsigned int msglevel)
 {
     struct status_output *so = status_open(NULL, 0, msglevel, NULL, 0);
     ASSERT(so);
src/openvpn/pool.h +1 -1
index 6cecef0..9c69512 100644
@@ -78,7 +78,7 @@
 
 void ifconfig_pool_free(struct ifconfig_pool *pool);
 
-bool ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end);
+bool ifconfig_pool_verify_range(const unsigned int msglevel, const in_addr_t start, const in_addr_t end);
 
 ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local,
                                            in_addr_t *remote, struct in6_addr *remote_ipv6,
src/openvpn/push.c +7 -7
index 671b015..d4019e5 100644
@@ -373,8 +373,8 @@
  *
  * @return true on success, false on failure.
  */
-static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel,
-                            const char *fmt, ...)
+static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                            unsigned int msglevel, const char *fmt, ...)
 #ifdef __GNUC__
 #if __USE_MINGW_ANSI_STDIO
     __attribute__((format(gnu_printf, 4, 5)))
@@ -857,7 +857,7 @@
 
 static void
 push_option_ex(struct gc_arena *gc, struct push_list *push_list, const char *opt, bool enable,
-               int msglevel)
+               unsigned int msglevel)
 {
     if (!string_class(opt, CC_ANY, CC_COMMA))
     {
@@ -885,7 +885,7 @@
 }
 
 void
-push_option(struct options *o, const char *opt, int msglevel)
+push_option(struct options *o, const char *opt, unsigned int msglevel)
 {
     push_option_ex(&o->gc, &o->push_list, opt, true, msglevel);
 }
@@ -906,7 +906,7 @@
 }
 
 void
-push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc)
+push_options(struct options *o, char **p, unsigned int msglevel, struct gc_arena *gc)
 {
     const char **argv = make_extended_arg_array(p, false, gc);
     char *opt = print_argv(argv, gc, 0);
@@ -914,8 +914,8 @@
 }
 
 static bool
-push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel, const char *format,
-                ...)
+push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                unsigned int msglevel, const char *format, ...)
 {
     va_list arglist;
     char tmp[256] = { 0 };
src/openvpn/push.h +2 -2
index 8ffd0c2..a13e24f 100644
@@ -99,9 +99,9 @@
 
 void clone_push_list(struct options *o);
 
-void push_option(struct options *o, const char *opt, int msglevel);
+void push_option(struct options *o, const char *opt, unsigned int msglevel);
 
-void push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc);
+void push_options(struct options *o, char **p, unsigned int msglevel, struct gc_arena *gc);
 
 void push_reset(struct options *o);
 
src/openvpn/route.c +13 -13
index d3d2954..72e763d 100644
@@ -1228,28 +1228,28 @@
 }
 
 static void
-print_route_option(const struct route_option *ro, int level)
+print_route_option(const struct route_option *ro, unsigned int msglevel)
 {
-    msg(level, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
+    msg(msglevel, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
         show_opt(ro->gateway), show_opt(ro->metric));
 }
 
 void
-print_route_options(const struct route_option_list *rol, int level)
+print_route_options(const struct route_option_list *rol, unsigned int msglevel)
 {
     struct route_option *ro;
     if (rol->flags & RG_ENABLE)
     {
-        msg(level, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
+        msg(msglevel, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
     }
     for (ro = rol->routes; ro; ro = ro->next)
     {
-        print_route_option(ro, level);
+        print_route_option(ro, msglevel);
     }
 }
 
 void
-print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+print_default_gateway(const unsigned int msglevel, const struct route_gateway_info *rgi,
                       const struct route_ipv6_gateway_info *rgi6)
 {
     struct gc_arena gc = gc_new();
@@ -1323,23 +1323,23 @@
 #endif /* ifndef ENABLE_SMALL */
 
 static void
-print_route(const struct route_ipv4 *r, int level)
+print_route(const struct route_ipv4 *r, unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     if (r->flags & RT_DEFINED)
     {
-        msg(level, "%s", route_string(r, &gc));
+        msg(msglevel, "%s", route_string(r, &gc));
     }
     gc_free(&gc);
 }
 
 void
-print_routes(const struct route_list *rl, int level)
+print_routes(const struct route_list *rl, unsigned int msglevel)
 {
     struct route_ipv4 *r;
     for (r = rl->routes; r; r = r->next)
     {
-        print_route(r, level);
+        print_route(r, msglevel);
     }
 }
 
@@ -3067,18 +3067,18 @@
  * Show current routing table
  */
 void
-show_routes(int msglev)
+show_routes(unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
 
     const MIB_IPFORWARDTABLE *rt = get_windows_routing_table(&gc);
 
-    msg(msglev, "SYSTEM ROUTING TABLE");
+    msg(msglevel, "SYSTEM ROUTING TABLE");
     if (rt)
     {
         for (DWORD i = 0; i < rt->dwNumEntries; ++i)
         {
-            msg(msglev, "%s", format_route_entry(&rt->table[i], &gc));
+            msg(msglevel, "%s", format_route_entry(&rt->table[i], &gc));
         }
     }
     gc_free(&gc);
src/openvpn/route.h +4 -4
index 9b6a47e..b8c8244 100644
@@ -356,7 +356,7 @@
 void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi, const struct in6_addr *dest,
                               openvpn_net_ctx_t *ctx);
 
-void print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+void print_default_gateway(const unsigned int msglevel, const struct route_gateway_info *rgi,
                            const struct route_ipv6_gateway_info *rgi6);
 
 /*
@@ -371,15 +371,15 @@
 int test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi);
 
 #ifndef ENABLE_SMALL
-void print_route_options(const struct route_option_list *rol, int level);
+void print_route_options(const struct route_option_list *rol, unsigned int msglevel);
 
 #endif
 
-void print_routes(const struct route_list *rl, int level);
+void print_routes(const struct route_list *rl, unsigned int msglevel);
 
 #ifdef _WIN32
 
-void show_routes(int msglev);
+void show_routes(unsigned int msglevel);
 
 bool test_routes(const struct route_list *rl, const struct tuntap *tt);
 
src/openvpn/run_command.c +1 -1
index 4a1ef22..942434c 100644
@@ -107,7 +107,7 @@
 
 #ifndef WIN32
 bool
-openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel)
+openvpn_waitpid_check(pid_t pid, const char *msg_prefix, unsigned int msglevel)
 {
     if (pid == 0)
     {
src/openvpn/run_command.h +5 -5
index afd1b88..222272c 100644
@@ -71,13 +71,13 @@
  * This function is currently not implemented for Windows as the helper
  * macros used by this function are not available.
  *
- * @param pid               pid of the process to be checked
+ * @param pid            pid of the process to be checked
  * @param msg_prefix     prefixed of the message that be printed
- * @param msglevel          msglevel of the messages to be printed
- * @return                  true if the process is still running, false if
- *                          an error condition occurred
+ * @param msglevel       msglevel of the messages to be printed
+ * @return               true if the process is still running, false if
+ *                       an error condition occurred
  */
-bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel);
+bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, unsigned int msglevel);
 
 #endif
 
src/openvpn/sig.c +1 -1
index ecea635..35c2249 100644
@@ -287,7 +287,7 @@
 }
 
 void
-print_signal(const struct signal_info *si, const char *title, int msglevel)
+print_signal(const struct signal_info *si, const char *title, unsigned int msglevel)
 {
     if (si)
     {
src/openvpn/sig.h +1 -1
index 7e5dd9f..06558d7 100644
@@ -66,7 +66,7 @@
 
 void restore_signal_state(void);
 
-void print_signal(const struct signal_info *si, const char *title, int msglevel);
+void print_signal(const struct signal_info *si, const char *title, unsigned int msglevel);
 
 void print_status(struct context *c, struct status_output *so);
 
src/openvpn/socket.c +4 -3
index 248c690..6f73514 100644
@@ -83,7 +83,7 @@
 static int
 get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname, void *network,
                  unsigned int *netbits, int resolve_retry_seconds, struct signal_info *sig_info,
-                 int msglevel)
+                 unsigned int msglevel)
 {
     char *endp, *sep, *var_host = NULL;
     struct addrinfo *ai = NULL;
@@ -216,7 +216,8 @@
 }
 
 bool
-get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
+get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
+              unsigned int msglevel)
 {
     if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostname, network, netbits, 0, NULL, msglevel)
         < 0)
@@ -1521,7 +1522,7 @@
 linksock_print_addr(struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
-    const int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
+    const unsigned int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
 
     /* print local address */
     if (sock->bind_local)
src/openvpn/socket_util.c +3 -3
index 9b7312d..454b151 100644
@@ -541,7 +541,7 @@
     struct addrinfo hints;
     int status;
     struct signal_info sigrec = { 0 };
-    int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
+    unsigned int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
     struct gc_arena gc = gc_new();
     const char *print_hostname;
     const char *print_servname;
@@ -604,7 +604,7 @@
         int resolve_retries =
             (flags & GETADDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) / fail_wait_interval);
         const char *fmt;
-        int level = 0;
+        unsigned int level = 0;
 
         /* this is not a numeric IP, therefore force resolution using the
          * provided ai_family */
@@ -739,7 +739,7 @@
 done:
     if (sig_info && sig_info->signal_received)
     {
-        int level = 0;
+        unsigned int level = 0;
         if (flags & GETADDR_FATAL_ON_SIGNAL)
         {
             level = M_FATAL;
src/openvpn/socket_util.h +1 -1
index 5ea37dd..6f92af1 100644
@@ -142,7 +142,7 @@
  * Translate an IPv6 addr or hostname from string form to in6_addr
  */
 bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
-                   int msglevel);
+                   unsigned int msglevel);
 
 int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname,
                         int resolve_retry_seconds, struct signal_info *sig_info, int ai_family,
src/openvpn/ssl_verify_backend.h +2 -2
index a0559c9..af7a08f 100644
@@ -193,8 +193,8 @@
  * @param gc            Garbage collection arena for temp data
  *
  */
-void x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
-                    struct gc_arena *gc);
+void x509_track_add(const struct x509_track **ll_head, const char *name,
+                    unsigned int msglevel, struct gc_arena *gc);
 
 /*
  * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_mbedtls.c +1 -1
index a2c702d..2ea410d 100644
@@ -359,7 +359,7 @@
 }
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, unsigned int msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/ssl_verify_openssl.c +1 -1
index 122101c..e3c18a4 100644
@@ -414,7 +414,7 @@
  */
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, unsigned int msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/status.c +2 -3
index fbd2168..a9f9498 100644
@@ -235,14 +235,13 @@
 
         if (so->msglevel >= 0 && !so->errors)
         {
-            msg(so->msglevel, "%s", buf);
+            msg((unsigned int)so->msglevel, "%s", buf);
         }
 
         if (so->fd >= 0 && !so->errors)
         {
-            int len;
             strcat(buf, "\n");
-            len = strlen(buf);
+            size_t len = strlen(buf);
             if (len > 0)
             {
                 if (write(so->fd, buf, len) != len)
src/openvpn/status.h +1 -0
index 0c7a869..25e1663 100644
@@ -53,6 +53,7 @@
 
     char *filename;
     int fd;
+    /* NB: -1 is used to indicate that output should only go to the file */
     int msglevel;
     const struct virtual_output *vout;
 
src/openvpn/tun.c +27 -27

146 lines not on this page · raw message

src/openvpn/tun.h +2 -2
index 06fc729..fd2d270 100644
@@ -445,9 +445,9 @@
 DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count,
                           in_addr_t *netmask);
 
-void show_tap_win_adapters(int msglev, int warnlev);
+void show_tap_win_adapters(unsigned int msglevel, unsigned int warnlevel);
 
-void show_adapters(int msglev);
+void show_adapters(unsigned int msglevel);
 
 void tap_allow_nonadmin_access(const char *dev_node);
 
tests/unit_tests/openvpn/mock_ssl_dependencies.c +1 -1
index 7333c47..3abab43 100644
@@ -38,7 +38,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_argv.c +1 -1
index a65857b..a4f9e84 100644
@@ -23,7 +23,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  unsigned int msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_misc.c +1 -1
index 8a86d71..6093de8 100644
@@ -348,7 +348,7 @@
     assert_false(valid_integer("-2147483653", false));
 
 
-    int msglevel = D_LOW;
+    unsigned int msglevel = D_LOW;
     int saved_log_level = mock_get_debug_level();
     mock_set_debug_level(D_LOW);
 
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
index 56125df..e14415d 100644
@@ -59,7 +59,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_pkt.c +1 -1
index 5122766..f349824 100644
@@ -45,7 +45,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_push_update_msg.c +1 -1
index 87329b1..f0d91d4 100644
@@ -120,7 +120,7 @@
 int i;
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, unsigned int msglevel)
 {
     if (res && res[i] && strcmp(res[i], str))
     {
tests/unit_tests/openvpn/test_tls_crypt.c +1 -1
index 532bfcd..e2b2e38 100644
@@ -98,7 +98,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  unsigned int msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_user_pass.c +1 -1
index 460b37f..30b0a73 100644
@@ -73,7 +73,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 11
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

Hello cron2, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email

to look at the new patch set (#12).

Change subject: Clean up the big msglevel type confusion
......................................................................

Clean up the big msglevel type confusion

msglevel was definitely unsigned as the first
argument to msg(), but many parts of the code
had it as signed. So this produced a LOT of
warnings when enabling -Wsign-conversion.

There is one exception in struct status_output
where -1 is a valid value in the API. Only
positive values are translated into standard
message levels.

Change-Id Id492cb774c6d022d06bb3cf5fec2a4bdd410e619

---
M src/openvpn/argv.c
M src/openvpn/argv.h
M src/openvpn/buffer.c
M src/openvpn/clinat.c
M src/openvpn/clinat.h
M src/openvpn/comp.c
M src/openvpn/comp.h
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/dco.c
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dns.c
M src/openvpn/dns.h
M src/openvpn/env_set.c
M src/openvpn/env_set.h
M src/openvpn/error.c
M src/openvpn/error.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/manage.h
M src/openvpn/mtu.c
M src/openvpn/mtu.h
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/packet_id.c
M src/openvpn/plugin.c
M src/openvpn/plugin.h
M src/openvpn/pool.c
M src/openvpn/pool.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/sig.c
M src/openvpn/sig.h
M src/openvpn/socket.c
M src/openvpn/socket_util.c
M src/openvpn/socket_util.h
M src/openvpn/ssl_verify_backend.h
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/status.c
M src/openvpn/status.h
M src/openvpn/tun.c
M src/openvpn/tun.h
M tests/unit_tests/openvpn/mock_ssl_dependencies.c M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_push_update_msg.c M tests/unit_tests/openvpn/test_tls_crypt.c M tests/unit_tests/openvpn/test_user_pass.c

63 files changed, 233 insertions(+), 225 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/1110/12

src/openvpn/argv.c +9 -9
index 903fc0a..55deef5 100644
@@ -235,14 +235,14 @@
 /**
  *  Write the arguments stored in a struct argv via the msg() command.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write.
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write.
  */
 void
-argv_msg(const int msglev, const struct argv *a)
+argv_msg(const unsigned int msglevel, const struct argv *a)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s", argv_str(a, &gc, 0));
+    msg(msglevel, "%s", argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
@@ -250,16 +250,16 @@
  *  Similar to argv_msg() but prefixes the messages being written with a
  *  given string.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write
- *  @param prefix  Valid pointer to the prefix string
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write
+ *  @param prefix    Valid pointer to the prefix string
  *
  */
 void
-argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix)
+argv_msg_prefix(const unsigned int msglevel, const struct argv *a, const char *prefix)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s: %s", prefix, argv_str(a, &gc, 0));
+    msg(msglevel, "%s: %s", prefix, argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
src/openvpn/argv.h +2 -2
index 056fe31..724b827 100644
@@ -47,9 +47,9 @@
 
 struct argv argv_insert_head(const struct argv *a, const char *head);
 
-void argv_msg(const int msglev, const struct argv *a);
+void argv_msg(const unsigned int msglevel, const struct argv *a);
 
-void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix);
+void argv_msg_prefix(const unsigned int msglevel, const struct argv *a, const char *prefix);
 
 void argv_parse_cmd(struct argv *a, const char *s);
 
src/openvpn/buffer.c +1 -1
index 0f0d17e..b6d6669 100644
@@ -1127,7 +1127,7 @@
 {
     if (buf && buf->len)
     {
-        int msglevel = D_ALIGN_DEBUG;
+        unsigned int msglevel = D_ALIGN_DEBUG;
         const unsigned int u = (unsigned int)BPTR(buf);
 
         if (u & (PAYLOAD_ALIGN - 1))
src/openvpn/clinat.c +3 -3
index 48a2057..2d21daf 100644
@@ -47,7 +47,7 @@
 }
 
 void
-print_client_nat_list(const struct client_nat_option_list *list, int msglevel)
+print_client_nat_list(const struct client_nat_option_list *list, unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     int i;
@@ -101,7 +101,7 @@
 void
 add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                               const char *network, const char *netmask, const char *foreign_network,
-                              int msglevel)
+                              unsigned int msglevel)
 {
     struct client_nat_entry e;
     bool ok;
@@ -159,7 +159,7 @@
 #endif
 
 static void
-print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const int msglevel)
+print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
 
src/openvpn/clinat.h +2 -2
index abfa0b7..3fcdf70 100644
@@ -54,11 +54,11 @@
 void copy_client_nat_option_list(struct client_nat_option_list *dest,
                                  const struct client_nat_option_list *src);
 
-void print_client_nat_list(const struct client_nat_option_list *list, int msglevel);
+void print_client_nat_list(const struct client_nat_option_list *list, unsigned int msglevel);
 
 void add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                                    const char *network, const char *netmask,
-                                   const char *foreign_network, int msglevel);
+                                   const char *foreign_network, unsigned int msglevel);
 
 void client_nat_transform(const struct client_nat_option_list *list, struct buffer *ipbuf,
                           const int direction);
src/openvpn/comp.c +1 -1
index 1a2e775..305184d 100644
@@ -159,7 +159,7 @@
 #endif /* USE_COMP */
 
 bool
-check_compression_settings_valid(struct compress_options *info, int msglevel)
+check_compression_settings_valid(struct compress_options *info, unsigned int msglevel)
 {
     /*
      * We also allow comp-stub-v2 here as it technically allows escaping of
src/openvpn/comp.h +1 -1
index 0354896..5327eae 100644
@@ -89,7 +89,7 @@
  * flags of allow-compression and also the whether algorithms are compiled
  * in
  */
-bool check_compression_settings_valid(struct compress_options *info, int msglevel);
+bool check_compression_settings_valid(struct compress_options *info, unsigned int msglevel);
 
 #ifdef USE_COMP
 #include "buffer.h"
src/openvpn/crypto.c +1 -1
index 1535c78..cec66da 100644
@@ -1618,7 +1618,7 @@
 }
 
 int
-ascii2keydirection(int msglevel, const char *str)
+ascii2keydirection(unsigned int msglevel, const char *str)
 {
     if (!str)
     {
src/openvpn/crypto.h +1 -1
index efd7f60..a403f32 100644
@@ -618,7 +618,7 @@
 
 void must_have_n_keys(const char *filename, const char *option, const struct key2 *key2, int n);
 
-int ascii2keydirection(int msglevel, const char *str);
+int ascii2keydirection(unsigned int msglevel, const char *str);
 
 const char *keydirection2ascii(int kd, bool remote, bool humanreadable);
 
src/openvpn/dco.c +4 -4
index 823b4f9..8f39e80 100644
@@ -233,7 +233,7 @@
 }
 
 static bool
-dco_check_option_ce(const struct connection_entry *ce, int msglevel, int mode)
+dco_check_option_ce(const struct connection_entry *ce, unsigned int msglevel, int mode)
 {
     if (ce->fragment)
     {
@@ -293,7 +293,7 @@
 }
 
 bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(unsigned int msglevel, const struct options *o)
 {
     /* check if no dev name was specified at all. In the case,
      * later logic will most likely stop OpenVPN, so no need to
@@ -430,7 +430,7 @@
 }
 
 bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(unsigned int msglevel, const struct options *o)
 {
     /* At this point the ciphers have already been normalised */
     if (o->enable_ncp_fallback
@@ -480,7 +480,7 @@
 }
 
 bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(unsigned int msglevel, const struct options *o)
 {
     if (!o->use_peer_id)
     {
src/openvpn/dco.h +8 -8
index 59acb18..7fa8055 100644
@@ -55,7 +55,7 @@
  * @param msglevel      level to print messages to
  * @return              true if ovpn-dco is available, false otherwise
  */
-bool dco_available(int msglevel);
+bool dco_available(unsigned int msglevel);
 
 
 /**
@@ -75,7 +75,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_option(int msglevel, const struct options *o);
+bool dco_check_option(unsigned int msglevel, const struct options *o);
 
 /**
  * Check whether the options struct has any further option that is not supported
@@ -87,7 +87,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_startup_option(int msglevel, const struct options *o);
+bool dco_check_startup_option(unsigned int msglevel, const struct options *o);
 
 /**
  * Check whether any of the options pushed by the server is not supported by
@@ -98,7 +98,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_pull_options(int msglevel, const struct options *o);
+bool dco_check_pull_options(unsigned int msglevel, const struct options *o);
 
 /**
  * Initialize the DCO context
@@ -261,7 +261,7 @@
 typedef void *dco_context_t;
 
 static inline bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     return false;
 }
@@ -273,19 +273,19 @@
 }
 
 static inline bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
src/openvpn/dco_freebsd.c +1 -1
index 56a774d..cb76211 100644
@@ -663,7 +663,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     struct if_clonereq ifcr;
     char *buf = NULL;
src/openvpn/dco_linux.c +2 -2
index 3b08f33..accd432 100644
@@ -79,7 +79,7 @@
  * @return ID on success, negative error code on error
  */
 static int
-resolve_ovpn_netlink_id(int msglevel)
+resolve_ovpn_netlink_id(unsigned int msglevel)
 {
     int ret;
     struct nl_sock *nl_sock = nl_socket_alloc();
@@ -1204,7 +1204,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0)
     {
src/openvpn/dco_win.c +1 -1
index 1dc5cf8..39a5ab6 100644
@@ -609,7 +609,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     /* try to open device by symbolic name */
     HANDLE h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
src/openvpn/dns.c +1 -1
index 5421004..6455cc9 100644
@@ -200,7 +200,7 @@
 }
 
 bool
-dns_options_verify(int msglevel, const struct dns_options *o)
+dns_options_verify(unsigned int msglevel, const struct dns_options *o)
 {
     const struct dns_server *server = o->servers ? o->servers : o->servers_prepull;
     while (server)
src/openvpn/dns.h +1 -1
index 6d97b40..833b937 100644
@@ -166,7 +166,7 @@
  * @param   o           Pointer to the DNS options to validate
  * @return              True if no error was found
  */
-bool dns_options_verify(int msglevel, const struct dns_options *o);
+bool dns_options_verify(unsigned int msglevel, const struct dns_options *o);
 
 /**
  * Makes a deep copy of the passed DNS options.
src/openvpn/env_set.c +1 -1
index 6c7df8e..487a5e2 100644
@@ -209,7 +209,7 @@
 }
 
 void
-env_set_print(int msglevel, const struct env_set *es)
+env_set_print(unsigned int msglevel, const struct env_set *es)
 {
     if (check_debug_level(msglevel))
     {
src/openvpn/env_set.h +1 -1
index 3973a4e..130de75 100644
@@ -85,7 +85,7 @@
 
 const char *env_set_get(const struct env_set *es, const char *name);
 
-void env_set_print(int msglevel, const struct env_set *es);
+void env_set_print(unsigned int msglevel, const struct env_set *es);
 
 /**
  * Write a struct env_set to a file. Each item on one line.
src/openvpn/error.c +2 -2
index 1b98235..90c0f75 100644
@@ -390,8 +390,8 @@
     bool ret = true;
     if (mute_cutoff > 0 && !(flags & M_NOMUTE))
     {
-        const int mute_level = DECODE_MUTE_LEVEL(flags);
-        if (mute_level > 0 && mute_level == mute_category)
+        const unsigned int mute_level = DECODE_MUTE_LEVEL(flags);
+        if (mute_level == mute_category)
         {
             if (mute_count == mute_cutoff)
             {
src/openvpn/error.h +14 -14
index 8388f82..2ad2c5d 100644
@@ -83,22 +83,22 @@
 
 /* msg() flags */
 
-#define M_DEBUG_LEVEL (0x0F) /* debug level mask */
+#define M_DEBUG_LEVEL (0x0Fu) /* debug level mask */
 
-#define M_FATAL    (1 << 4)  /* exit program */
-#define M_NONFATAL (1 << 5)  /* non-fatal error */
-#define M_WARN     (1 << 6)  /* call syslog with LOG_WARNING */
-#define M_DEBUG    (1 << 7)
+#define M_FATAL    (1u << 4)  /* exit program */
+#define M_NONFATAL (1u << 5)  /* non-fatal error */
+#define M_WARN     (1u << 6)  /* call syslog with LOG_WARNING */
+#define M_DEBUG    (1u << 7)
 
-#define M_ERRNO (1 << 8)         /* show errno description */
+#define M_ERRNO (1u << 8)         /* show errno description */
 
-#define M_NOMUTE       (1 << 11) /* don't do mute processing */
-#define M_NOPREFIX     (1 << 12) /* don't show date/time prefix */
-#define M_USAGE_SMALL  (1 << 13) /* fatal options error, call usage_small */
-#define M_MSG_VIRT_OUT (1 << 14) /* output message through msg_status_output callback */
-#define M_OPTERR       (1 << 15) /* print "Options error:" prefix */
-#define M_NOLF         (1 << 16) /* don't print new line */
-#define M_NOIPREFIX    (1 << 17) /* don't print instance prefix */
+#define M_NOMUTE       (1u << 11) /* don't do mute processing */
+#define M_NOPREFIX     (1u << 12) /* don't show date/time prefix */
+#define M_USAGE_SMALL  (1u << 13) /* fatal options error, call usage_small */
+#define M_MSG_VIRT_OUT (1u << 14) /* output message through msg_status_output callback */
+#define M_OPTERR       (1u << 15) /* print "Options error:" prefix */
+#define M_NOLF         (1u << 16) /* don't print new line */
+#define M_NOIPREFIX    (1u << 17) /* don't print instance prefix */
 
 /* flag combinations which are frequently used */
 #define M_ERR    (M_FATAL | M_ERRNO)
@@ -112,7 +112,7 @@
  * A mute level of 0 is always printed.
  */
 #define MUTE_LEVEL_SHIFT 24
-#define MUTE_LEVEL_MASK  0xFF
+#define MUTE_LEVEL_MASK  0xFFu
 
 #define ENCODE_MUTE_LEVEL(mute_level) (((mute_level) & MUTE_LEVEL_MASK) << MUTE_LEVEL_SHIFT)
 #define DECODE_MUTE_LEVEL(flags)      (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEVEL_MASK)
src/openvpn/forward.c +3 -2
index e82b544..cafd8e75 100644
@@ -373,7 +373,8 @@
 #endif
 
 bool
-send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel)
+send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                   unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     bool stat;
@@ -400,7 +401,7 @@
 }
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, unsigned int msglevel)
 {
     if (c->c2.tls_multi)
     {
src/openvpn/forward.h +3 -2
index 79d0f8b..581eae1 100644
@@ -285,7 +285,7 @@
  * @param str        - The message to be sent
  * @param msglevel   - Message level to use for logging
  */
-bool send_control_channel_string(struct context *c, const char *str, int msglevel);
+bool send_control_channel_string(struct context *c, const char *str, unsigned int msglevel);
 
 /*
  * Send a string to remote over the TLS control channel.
@@ -303,7 +303,8 @@
  * @param msglevel   - Message level to use for logging
  */
 
-bool send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel);
+bool send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                        unsigned int msglevel);
 
 
 /**
src/openvpn/init.c +1 -1
index 24aebc0..e6b3b14 100644
@@ -4282,7 +4282,7 @@
 }
 
 void
-management_show_net_callback(void *arg, const int msglevel)
+management_show_net_callback(void *arg, const unsigned int msglevel)
 {
 #ifdef _WIN32
     show_routes(msglevel);
src/openvpn/init.h +1 -1
index a807874..432cf31 100644
@@ -136,7 +136,7 @@
 
 void close_management(void);
 
-void management_show_net_callback(void *arg, const int msglevel);
+void management_show_net_callback(void *arg, const unsigned int msglevel);
 
 #endif
 
src/openvpn/manage.h +1 -1
index 7c189ba..4b62b04 100644
@@ -176,7 +176,7 @@
     unsigned int flags;
 
     void (*status)(void *arg, const int version, struct status_output *so);
-    void (*show_net)(void *arg, const int msglevel);
+    void (*show_net)(void *arg, const unsigned int msglevel);
     int (*kill_by_cn)(void *arg, const char *common_name);
     int (*kill_by_addr)(void *arg, const in_addr_t addr, const int port, const int proto);
     void (*delete_event)(void *arg, event_t event);
src/openvpn/mtu.c +2 -2
index 1e021e3..f5bc814 100644
@@ -187,7 +187,7 @@
 }
 
 void
-frame_print(const struct frame *frame, int level, const char *prefix)
+frame_print(const struct frame *frame, unsigned int msglevel, const char *prefix)
 {
     struct gc_arena gc = gc_new();
     struct buffer out = alloc_buf_gc(256, &gc);
@@ -208,7 +208,7 @@
     buf_printf(&out, " ET:%d", frame->extra_tun);
     buf_printf(&out, " ]");
 
-    msg(level, "%s", out.data);
+    msg(msglevel, "%s", out.data);
     gc_free(&gc);
 }
 
src/openvpn/mtu.h +1 -1
index c092461..c555f51 100644
@@ -181,7 +181,7 @@
  * Function prototypes.
  */
 
-void frame_print(const struct frame *frame, int level, const char *prefix);
+void frame_print(const struct frame *frame, unsigned int msglevel, const char *prefix);
 
 void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af);
 
src/openvpn/multi.c +1 -1
index 579eeea..a68832b 100644
@@ -3321,7 +3321,7 @@
     }
     else
     {
-        int msglevel = D_DCO;
+        unsigned int msglevel = D_DCO;
         if (dco->dco_message_type == OVPN_CMD_DEL_PEER
             && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
         {
src/openvpn/options.c +52 -48

330 lines not on this page · raw message

src/openvpn/options.h +6 -6
index bb2c052..5e918bb 100644
@@ -822,7 +822,7 @@
     struct pull_filter *tail;
 };
 
-void parse_argv(struct options *options, const int argc, char *argv[], const int msglevel,
+void parse_argv(struct options *options, const int argc, char *argv[], const unsigned int msglevel,
                 const unsigned int permission_mask, unsigned int *option_types_found,
                 struct env_set *es);
 
@@ -888,7 +888,7 @@
 
 void options_detach(struct options *o);
 
-void options_server_import(struct options *o, const char *filename, int msglevel,
+void options_server_import(struct options *o, const char *filename, unsigned int msglevel,
                            unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
@@ -897,13 +897,13 @@
 void rol_check_alloc(struct options *options);
 
 int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num,
-               int msglevel, struct gc_arena *gc);
+               unsigned int msglevel, struct gc_arena *gc);
 
 /*
  * parse/print topology coding
  */
 
-int parse_topology(const char *str, const int msglevel);
+int parse_topology(const char *str, const unsigned int msglevel);
 
 const char *print_topology(const int topology);
 
@@ -917,11 +917,11 @@
 
 int auth_retry_get(void);
 
-bool auth_retry_set(const int msglevel, const char *option);
+bool auth_retry_set(const unsigned int msglevel, const char *option);
 
 const char *auth_retry_print(void);
 
-void options_string_import(struct options *options, const char *config, const int msglevel,
+void options_string_import(struct options *options, const char *config, const unsigned int msglevel,
                            const unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
src/openvpn/options_util.c +2 -2
index a351967..6d1eb21 100644
@@ -117,7 +117,7 @@
 }
 
 int
-positive_atoi(const char *str, int msglevel)
+positive_atoi(const char *str, unsigned int msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -148,7 +148,7 @@
 }
 
 int
-atoi_warn(const char *str, int msglevel)
+atoi_warn(const char *str, unsigned int msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
src/openvpn/options_util.h +2 -2
index 45417d9..f7df101 100644
@@ -37,7 +37,7 @@
  * Converts a str to a positive number if the string represents a postive
  * integer number. Otherwise print a warning with msglevel and return 0
  */
-int positive_atoi(const char *str, int msglevel);
+int positive_atoi(const char *str, unsigned int msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -54,7 +54,7 @@
  * Converts a str to an integer if the string can be represented as an
  * integer number. Otherwise print a warning with \p msglevel and return 0
  */
-int atoi_warn(const char *str, int msglevel);
+int atoi_warn(const char *str, unsigned int msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
src/openvpn/packet_id.c +5 -4
index 0b33c9c..63a4cae 100644
@@ -53,15 +53,15 @@
 #define SEQ_EXPIRED ((time_t)1)
 
 #ifdef ENABLE_DEBUG
-static void packet_id_debug_print(int msglevel, const struct packet_id_rec *p,
+static void packet_id_debug_print(unsigned int msglevel, const struct packet_id_rec *p,
                                   const struct packet_id_net *pin, const char *message,
                                   packet_id_print_type value);
 
 #endif /* ENABLE_DEBUG */
 
 static inline void
-packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
-                const char *message, uint64_t value)
+packet_id_debug(unsigned int msglevel, const struct packet_id_rec *p,
+                const struct packet_id_net *pin, const char *message, uint64_t value)
 {
 #ifdef ENABLE_DEBUG
     if (unlikely(check_debug_level(msglevel)))
@@ -578,7 +578,8 @@
 #ifdef ENABLE_DEBUG
 
 static void
-packet_id_debug_print(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
+packet_id_debug_print(unsigned int msglevel, const struct packet_id_rec *p,
+                      const struct packet_id_net *pin,
                       const char *message, packet_id_print_type value)
 {
     struct gc_arena gc = gc_new();
src/openvpn/plugin.c +4 -4
index ea76a08..8223a2c 100644
@@ -50,7 +50,7 @@
 static struct plugin_common *static_plugin_common = NULL; /* GLOBAL */
 
 static void
-plugin_show_string_array(int msglevel, const char *name, const char *array[])
+plugin_show_string_array(unsigned int msglevel, const char *name, const char *array[])
 {
     int i;
     for (i = 0; array[i]; ++i)
@@ -63,7 +63,7 @@
 }
 
 static void
-plugin_show_args_env(int msglevel, const char *argv[], const char *envp[])
+plugin_show_args_env(unsigned int msglevel, const char *argv[], const char *envp[])
 {
     if (check_debug_level(msglevel))
     {
@@ -184,7 +184,7 @@
 
 #ifndef ENABLE_SMALL
 void
-plugin_option_list_print(const struct plugin_option_list *list, int msglevel)
+plugin_option_list_print(const struct plugin_option_list *list, unsigned int msglevel)
 {
     int i;
     struct gc_arena gc = gc_new();
@@ -995,7 +995,7 @@
 
 #ifdef ENABLE_DEBUG
 void
-plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr)
+plugin_return_print(const unsigned int msglevel, const char *prefix, const struct plugin_return *pr)
 {
     int i;
     msg(msglevel, "PLUGIN_RETURN_PRINT %s", prefix);
src/openvpn/plugin.h +2 -2
index 63999b6..91d3fba 100644
@@ -111,7 +111,7 @@
 bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc);
 
 #ifndef ENABLE_SMALL
-void plugin_option_list_print(const struct plugin_option_list *list, int msglevel);
+void plugin_option_list_print(const struct plugin_option_list *list, unsigned int msglevel);
 
 #endif
 
@@ -136,7 +136,7 @@
 void plugin_return_free(struct plugin_return *pr);
 
 #ifdef ENABLE_DEBUG
-void plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr);
+void plugin_return_print(const unsigned int msglevel, const char *prefix, const struct plugin_return *pr);
 
 #endif
 
src/openvpn/pool.c +2 -2
index fde6cea..0e95c5e 100644
@@ -114,7 +114,7 @@
  * Verify start/end range
  */
 bool
-ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end)
+ifconfig_pool_verify_range(const unsigned int msglevel, const in_addr_t start, const in_addr_t end)
 {
     struct gc_arena gc = gc_new();
     bool ret = true;
@@ -521,7 +521,7 @@
 }
 
 static void
-ifconfig_pool_msg(const struct ifconfig_pool *pool, int msglevel)
+ifconfig_pool_msg(const struct ifconfig_pool *pool, unsigned int msglevel)
 {
     struct status_output *so = status_open(NULL, 0, msglevel, NULL, 0);
     ASSERT(so);
src/openvpn/pool.h +1 -1
index 6cecef0..9c69512 100644
@@ -78,7 +78,7 @@
 
 void ifconfig_pool_free(struct ifconfig_pool *pool);
 
-bool ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end);
+bool ifconfig_pool_verify_range(const unsigned int msglevel, const in_addr_t start, const in_addr_t end);
 
 ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local,
                                            in_addr_t *remote, struct in6_addr *remote_ipv6,
src/openvpn/push.c +7 -7
index 671b015..d4019e5 100644
@@ -373,8 +373,8 @@
  *
  * @return true on success, false on failure.
  */
-static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel,
-                            const char *fmt, ...)
+static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                            unsigned int msglevel, const char *fmt, ...)
 #ifdef __GNUC__
 #if __USE_MINGW_ANSI_STDIO
     __attribute__((format(gnu_printf, 4, 5)))
@@ -857,7 +857,7 @@
 
 static void
 push_option_ex(struct gc_arena *gc, struct push_list *push_list, const char *opt, bool enable,
-               int msglevel)
+               unsigned int msglevel)
 {
     if (!string_class(opt, CC_ANY, CC_COMMA))
     {
@@ -885,7 +885,7 @@
 }
 
 void
-push_option(struct options *o, const char *opt, int msglevel)
+push_option(struct options *o, const char *opt, unsigned int msglevel)
 {
     push_option_ex(&o->gc, &o->push_list, opt, true, msglevel);
 }
@@ -906,7 +906,7 @@
 }
 
 void
-push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc)
+push_options(struct options *o, char **p, unsigned int msglevel, struct gc_arena *gc)
 {
     const char **argv = make_extended_arg_array(p, false, gc);
     char *opt = print_argv(argv, gc, 0);
@@ -914,8 +914,8 @@
 }
 
 static bool
-push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel, const char *format,
-                ...)
+push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                unsigned int msglevel, const char *format, ...)
 {
     va_list arglist;
     char tmp[256] = { 0 };
src/openvpn/push.h +2 -2
index 8ffd0c2..a13e24f 100644
@@ -99,9 +99,9 @@
 
 void clone_push_list(struct options *o);
 
-void push_option(struct options *o, const char *opt, int msglevel);
+void push_option(struct options *o, const char *opt, unsigned int msglevel);
 
-void push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc);
+void push_options(struct options *o, char **p, unsigned int msglevel, struct gc_arena *gc);
 
 void push_reset(struct options *o);
 
src/openvpn/route.c +13 -13
index d3d2954..72e763d 100644
@@ -1228,28 +1228,28 @@
 }
 
 static void
-print_route_option(const struct route_option *ro, int level)
+print_route_option(const struct route_option *ro, unsigned int msglevel)
 {
-    msg(level, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
+    msg(msglevel, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
         show_opt(ro->gateway), show_opt(ro->metric));
 }
 
 void
-print_route_options(const struct route_option_list *rol, int level)
+print_route_options(const struct route_option_list *rol, unsigned int msglevel)
 {
     struct route_option *ro;
     if (rol->flags & RG_ENABLE)
     {
-        msg(level, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
+        msg(msglevel, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
     }
     for (ro = rol->routes; ro; ro = ro->next)
     {
-        print_route_option(ro, level);
+        print_route_option(ro, msglevel);
     }
 }
 
 void
-print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+print_default_gateway(const unsigned int msglevel, const struct route_gateway_info *rgi,
                       const struct route_ipv6_gateway_info *rgi6)
 {
     struct gc_arena gc = gc_new();
@@ -1323,23 +1323,23 @@
 #endif /* ifndef ENABLE_SMALL */
 
 static void
-print_route(const struct route_ipv4 *r, int level)
+print_route(const struct route_ipv4 *r, unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     if (r->flags & RT_DEFINED)
     {
-        msg(level, "%s", route_string(r, &gc));
+        msg(msglevel, "%s", route_string(r, &gc));
     }
     gc_free(&gc);
 }
 
 void
-print_routes(const struct route_list *rl, int level)
+print_routes(const struct route_list *rl, unsigned int msglevel)
 {
     struct route_ipv4 *r;
     for (r = rl->routes; r; r = r->next)
     {
-        print_route(r, level);
+        print_route(r, msglevel);
     }
 }
 
@@ -3067,18 +3067,18 @@
  * Show current routing table
  */
 void
-show_routes(int msglev)
+show_routes(unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
 
     const MIB_IPFORWARDTABLE *rt = get_windows_routing_table(&gc);
 
-    msg(msglev, "SYSTEM ROUTING TABLE");
+    msg(msglevel, "SYSTEM ROUTING TABLE");
     if (rt)
     {
         for (DWORD i = 0; i < rt->dwNumEntries; ++i)
         {
-            msg(msglev, "%s", format_route_entry(&rt->table[i], &gc));
+            msg(msglevel, "%s", format_route_entry(&rt->table[i], &gc));
         }
     }
     gc_free(&gc);
src/openvpn/route.h +4 -4
index 9b6a47e..b8c8244 100644
@@ -356,7 +356,7 @@
 void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi, const struct in6_addr *dest,
                               openvpn_net_ctx_t *ctx);
 
-void print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+void print_default_gateway(const unsigned int msglevel, const struct route_gateway_info *rgi,
                            const struct route_ipv6_gateway_info *rgi6);
 
 /*
@@ -371,15 +371,15 @@
 int test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi);
 
 #ifndef ENABLE_SMALL
-void print_route_options(const struct route_option_list *rol, int level);
+void print_route_options(const struct route_option_list *rol, unsigned int msglevel);
 
 #endif
 
-void print_routes(const struct route_list *rl, int level);
+void print_routes(const struct route_list *rl, unsigned int msglevel);
 
 #ifdef _WIN32
 
-void show_routes(int msglev);
+void show_routes(unsigned int msglevel);
 
 bool test_routes(const struct route_list *rl, const struct tuntap *tt);
 
src/openvpn/run_command.c +1 -1
index 4a1ef22..942434c 100644
@@ -107,7 +107,7 @@
 
 #ifndef WIN32
 bool
-openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel)
+openvpn_waitpid_check(pid_t pid, const char *msg_prefix, unsigned int msglevel)
 {
     if (pid == 0)
     {
src/openvpn/run_command.h +5 -5
index afd1b88..222272c 100644
@@ -71,13 +71,13 @@
  * This function is currently not implemented for Windows as the helper
  * macros used by this function are not available.
  *
- * @param pid               pid of the process to be checked
+ * @param pid            pid of the process to be checked
  * @param msg_prefix     prefixed of the message that be printed
- * @param msglevel          msglevel of the messages to be printed
- * @return                  true if the process is still running, false if
- *                          an error condition occurred
+ * @param msglevel       msglevel of the messages to be printed
+ * @return               true if the process is still running, false if
+ *                       an error condition occurred
  */
-bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel);
+bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, unsigned int msglevel);
 
 #endif
 
src/openvpn/sig.c +1 -1
index ecea635..35c2249 100644
@@ -287,7 +287,7 @@
 }
 
 void
-print_signal(const struct signal_info *si, const char *title, int msglevel)
+print_signal(const struct signal_info *si, const char *title, unsigned int msglevel)
 {
     if (si)
     {
src/openvpn/sig.h +1 -1
index 7e5dd9f..06558d7 100644
@@ -66,7 +66,7 @@
 
 void restore_signal_state(void);
 
-void print_signal(const struct signal_info *si, const char *title, int msglevel);
+void print_signal(const struct signal_info *si, const char *title, unsigned int msglevel);
 
 void print_status(struct context *c, struct status_output *so);
 
src/openvpn/socket.c +4 -3
index 248c690..6f73514 100644
@@ -83,7 +83,7 @@
 static int
 get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname, void *network,
                  unsigned int *netbits, int resolve_retry_seconds, struct signal_info *sig_info,
-                 int msglevel)
+                 unsigned int msglevel)
 {
     char *endp, *sep, *var_host = NULL;
     struct addrinfo *ai = NULL;
@@ -216,7 +216,8 @@
 }
 
 bool
-get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
+get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
+              unsigned int msglevel)
 {
     if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostname, network, netbits, 0, NULL, msglevel)
         < 0)
@@ -1521,7 +1522,7 @@
 linksock_print_addr(struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
-    const int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
+    const unsigned int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
 
     /* print local address */
     if (sock->bind_local)
src/openvpn/socket_util.c +3 -3
index 9b7312d..454b151 100644
@@ -541,7 +541,7 @@
     struct addrinfo hints;
     int status;
     struct signal_info sigrec = { 0 };
-    int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
+    unsigned int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
     struct gc_arena gc = gc_new();
     const char *print_hostname;
     const char *print_servname;
@@ -604,7 +604,7 @@
         int resolve_retries =
             (flags & GETADDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) / fail_wait_interval);
         const char *fmt;
-        int level = 0;
+        unsigned int level = 0;
 
         /* this is not a numeric IP, therefore force resolution using the
          * provided ai_family */
@@ -739,7 +739,7 @@
 done:
     if (sig_info && sig_info->signal_received)
     {
-        int level = 0;
+        unsigned int level = 0;
         if (flags & GETADDR_FATAL_ON_SIGNAL)
         {
             level = M_FATAL;
src/openvpn/socket_util.h +1 -1
index 361edff..8a30527 100644
@@ -142,7 +142,7 @@
  * Translate an IPv6 addr or hostname from string form to in6_addr
  */
 bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
-                   int msglevel);
+                   unsigned int msglevel);
 
 int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname,
                         int resolve_retry_seconds, struct signal_info *sig_info, int ai_family,
src/openvpn/ssl_verify_backend.h +2 -2
index a0559c9..af7a08f 100644
@@ -193,8 +193,8 @@
  * @param gc            Garbage collection arena for temp data
  *
  */
-void x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
-                    struct gc_arena *gc);
+void x509_track_add(const struct x509_track **ll_head, const char *name,
+                    unsigned int msglevel, struct gc_arena *gc);
 
 /*
  * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_mbedtls.c +1 -1
index a2c702d..2ea410d 100644
@@ -359,7 +359,7 @@
 }
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, unsigned int msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/ssl_verify_openssl.c +1 -1
index 122101c..e3c18a4 100644
@@ -414,7 +414,7 @@
  */
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, unsigned int msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/status.c +2 -3
index fbd2168..a9f9498 100644
@@ -235,14 +235,13 @@
 
         if (so->msglevel >= 0 && !so->errors)
         {
-            msg(so->msglevel, "%s", buf);
+            msg((unsigned int)so->msglevel, "%s", buf);
         }
 
         if (so->fd >= 0 && !so->errors)
         {
-            int len;
             strcat(buf, "\n");
-            len = strlen(buf);
+            size_t len = strlen(buf);
             if (len > 0)
             {
                 if (write(so->fd, buf, len) != len)
src/openvpn/status.h +1 -0
index 0c7a869..25e1663 100644
@@ -53,6 +53,7 @@
 
     char *filename;
     int fd;
+    /* NB: -1 is used to indicate that output should only go to the file */
     int msglevel;
     const struct virtual_output *vout;
 
src/openvpn/tun.c +27 -27

146 lines not on this page · raw message

src/openvpn/tun.h +2 -2
index 06fc729..fd2d270 100644
@@ -445,9 +445,9 @@
 DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count,
                           in_addr_t *netmask);
 
-void show_tap_win_adapters(int msglev, int warnlev);
+void show_tap_win_adapters(unsigned int msglevel, unsigned int warnlevel);
 
-void show_adapters(int msglev);
+void show_adapters(unsigned int msglevel);
 
 void tap_allow_nonadmin_access(const char *dev_node);
 
tests/unit_tests/openvpn/mock_ssl_dependencies.c +1 -1
index 7333c47..3abab43 100644
@@ -38,7 +38,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_argv.c +1 -1
index a65857b..a4f9e84 100644
@@ -23,7 +23,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  unsigned int msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_misc.c +1 -1
index 3433b73..5348e53 100644
@@ -348,7 +348,7 @@
     assert_false(valid_integer("-2147483653", false));
 
 
-    int msglevel = D_LOW;
+    unsigned int msglevel = D_LOW;
     int saved_log_level = mock_get_debug_level();
     mock_set_debug_level(D_LOW);
 
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
index 9ba6cfc..1519fd6 100644
@@ -59,7 +59,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_pkt.c +1 -1
index 5122766..f349824 100644
@@ -45,7 +45,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_push_update_msg.c +2 -2
index 87329b1..8948f7b 100644
@@ -111,7 +111,7 @@
 
 #ifndef ENABLE_MANAGEMENT
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, unsigned int msglevel)
 {
     return true;
 }
@@ -120,7 +120,7 @@
 int i;
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, unsigned int msglevel)
 {
     if (res && res[i] && strcmp(res[i], str))
     {
tests/unit_tests/openvpn/test_tls_crypt.c +1 -1
index 532bfcd..e2b2e38 100644
@@ -98,7 +98,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  unsigned int msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_user_pass.c +1 -1
index 460b37f..30b0a73 100644
@@ -73,7 +73,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 12
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email )

Change subject: Clean up the big msglevel type confusion
......................................................................

Patch Set 12:

(1 comment)

Patchset:

PS10:

Quoted 1 line

Would it be less noisy and less space-consuming to change the other users to always use "int" instea […]

I just checked both patches and honestly it immediately looked weird to me that "flags" are stored in a "signed" container. Just as an example: normally flags are printed in hex format with %x - this one obviously doesn't expect a signed int.

I'd much rather go with this patch and drop #1189

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 12
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 15 Sep 2025 15:13:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email )

Change subject: Clean up the big msglevel type confusion
......................................................................

Set Ready For Review

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 12
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 15 Sep 2025 15:14:12 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#8 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, plaisthos.

Hello cron2, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email

to look at the new patch set (#14).

Change subject: Clean up the big msglevel type confusion
......................................................................

Clean up the big msglevel type confusion

msglevel was definitely unsigned as the first
argument to msg(), but many parts of the code
had it as signed. So this produced a LOT of
warnings when enabling -Wsign-conversion.

There is one exception in struct status_output
where -1 is a valid value in the API. Only
positive values are translated into standard
message levels.

Change-Id Id492cb774c6d022d06bb3cf5fec2a4bdd410e619

---
M src/openvpn/argv.c
M src/openvpn/argv.h
M src/openvpn/buffer.c
M src/openvpn/clinat.c
M src/openvpn/clinat.h
M src/openvpn/comp.c
M src/openvpn/comp.h
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/dco.c
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dns.c
M src/openvpn/dns.h
M src/openvpn/env_set.c
M src/openvpn/env_set.h
M src/openvpn/error.c
M src/openvpn/error.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/manage.h
M src/openvpn/mtu.c
M src/openvpn/mtu.h
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/packet_id.c
M src/openvpn/plugin.c
M src/openvpn/plugin.h
M src/openvpn/pool.c
M src/openvpn/pool.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/sig.c
M src/openvpn/sig.h
M src/openvpn/socket.c
M src/openvpn/socket_util.c
M src/openvpn/socket_util.h
M src/openvpn/ssl_verify_backend.h
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/status.c
M src/openvpn/status.h
M src/openvpn/tun.c
M src/openvpn/tun.h
M tests/unit_tests/openvpn/mock_ssl_dependencies.c M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_push_update_msg.c M tests/unit_tests/openvpn/test_tls_crypt.c M tests/unit_tests/openvpn/test_user_pass.c

63 files changed, 238 insertions(+), 229 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/1110/14

src/openvpn/argv.c +9 -9
index 903fc0a..55deef5 100644
@@ -235,14 +235,14 @@
 /**
  *  Write the arguments stored in a struct argv via the msg() command.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write.
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write.
  */
 void
-argv_msg(const int msglev, const struct argv *a)
+argv_msg(const unsigned int msglevel, const struct argv *a)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s", argv_str(a, &gc, 0));
+    msg(msglevel, "%s", argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
@@ -250,16 +250,16 @@
  *  Similar to argv_msg() but prefixes the messages being written with a
  *  given string.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write
- *  @param prefix  Valid pointer to the prefix string
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write
+ *  @param prefix    Valid pointer to the prefix string
  *
  */
 void
-argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix)
+argv_msg_prefix(const unsigned int msglevel, const struct argv *a, const char *prefix)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s: %s", prefix, argv_str(a, &gc, 0));
+    msg(msglevel, "%s: %s", prefix, argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
src/openvpn/argv.h +2 -2
index 056fe31..724b827 100644
@@ -47,9 +47,9 @@
 
 struct argv argv_insert_head(const struct argv *a, const char *head);
 
-void argv_msg(const int msglev, const struct argv *a);
+void argv_msg(const unsigned int msglevel, const struct argv *a);
 
-void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix);
+void argv_msg_prefix(const unsigned int msglevel, const struct argv *a, const char *prefix);
 
 void argv_parse_cmd(struct argv *a, const char *s);
 
src/openvpn/buffer.c +1 -1
index 0f0d17e..b6d6669 100644
@@ -1127,7 +1127,7 @@
 {
     if (buf && buf->len)
     {
-        int msglevel = D_ALIGN_DEBUG;
+        unsigned int msglevel = D_ALIGN_DEBUG;
         const unsigned int u = (unsigned int)BPTR(buf);
 
         if (u & (PAYLOAD_ALIGN - 1))
src/openvpn/clinat.c +3 -3
index 48a2057..2d21daf 100644
@@ -47,7 +47,7 @@
 }
 
 void
-print_client_nat_list(const struct client_nat_option_list *list, int msglevel)
+print_client_nat_list(const struct client_nat_option_list *list, unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     int i;
@@ -101,7 +101,7 @@
 void
 add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                               const char *network, const char *netmask, const char *foreign_network,
-                              int msglevel)
+                              unsigned int msglevel)
 {
     struct client_nat_entry e;
     bool ok;
@@ -159,7 +159,7 @@
 #endif
 
 static void
-print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const int msglevel)
+print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
 
src/openvpn/clinat.h +2 -2
index abfa0b7..3fcdf70 100644
@@ -54,11 +54,11 @@
 void copy_client_nat_option_list(struct client_nat_option_list *dest,
                                  const struct client_nat_option_list *src);
 
-void print_client_nat_list(const struct client_nat_option_list *list, int msglevel);
+void print_client_nat_list(const struct client_nat_option_list *list, unsigned int msglevel);
 
 void add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                                    const char *network, const char *netmask,
-                                   const char *foreign_network, int msglevel);
+                                   const char *foreign_network, unsigned int msglevel);
 
 void client_nat_transform(const struct client_nat_option_list *list, struct buffer *ipbuf,
                           const int direction);
src/openvpn/comp.c +1 -1
index 1a2e775..305184d 100644
@@ -159,7 +159,7 @@
 #endif /* USE_COMP */
 
 bool
-check_compression_settings_valid(struct compress_options *info, int msglevel)
+check_compression_settings_valid(struct compress_options *info, unsigned int msglevel)
 {
     /*
      * We also allow comp-stub-v2 here as it technically allows escaping of
src/openvpn/comp.h +1 -1
index 0354896..5327eae 100644
@@ -89,7 +89,7 @@
  * flags of allow-compression and also the whether algorithms are compiled
  * in
  */
-bool check_compression_settings_valid(struct compress_options *info, int msglevel);
+bool check_compression_settings_valid(struct compress_options *info, unsigned int msglevel);
 
 #ifdef USE_COMP
 #include "buffer.h"
src/openvpn/crypto.c +1 -1
index 1535c78..cec66da 100644
@@ -1618,7 +1618,7 @@
 }
 
 int
-ascii2keydirection(int msglevel, const char *str)
+ascii2keydirection(unsigned int msglevel, const char *str)
 {
     if (!str)
     {
src/openvpn/crypto.h +1 -1
index efd7f60..a403f32 100644
@@ -618,7 +618,7 @@
 
 void must_have_n_keys(const char *filename, const char *option, const struct key2 *key2, int n);
 
-int ascii2keydirection(int msglevel, const char *str);
+int ascii2keydirection(unsigned int msglevel, const char *str);
 
 const char *keydirection2ascii(int kd, bool remote, bool humanreadable);
 
src/openvpn/dco.c +4 -4
index 823b4f9..8f39e80 100644
@@ -233,7 +233,7 @@
 }
 
 static bool
-dco_check_option_ce(const struct connection_entry *ce, int msglevel, int mode)
+dco_check_option_ce(const struct connection_entry *ce, unsigned int msglevel, int mode)
 {
     if (ce->fragment)
     {
@@ -293,7 +293,7 @@
 }
 
 bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(unsigned int msglevel, const struct options *o)
 {
     /* check if no dev name was specified at all. In the case,
      * later logic will most likely stop OpenVPN, so no need to
@@ -430,7 +430,7 @@
 }
 
 bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(unsigned int msglevel, const struct options *o)
 {
     /* At this point the ciphers have already been normalised */
     if (o->enable_ncp_fallback
@@ -480,7 +480,7 @@
 }
 
 bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(unsigned int msglevel, const struct options *o)
 {
     if (!o->use_peer_id)
     {
src/openvpn/dco.h +8 -8
index 59acb18..7fa8055 100644
@@ -55,7 +55,7 @@
  * @param msglevel      level to print messages to
  * @return              true if ovpn-dco is available, false otherwise
  */
-bool dco_available(int msglevel);
+bool dco_available(unsigned int msglevel);
 
 
 /**
@@ -75,7 +75,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_option(int msglevel, const struct options *o);
+bool dco_check_option(unsigned int msglevel, const struct options *o);
 
 /**
  * Check whether the options struct has any further option that is not supported
@@ -87,7 +87,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_startup_option(int msglevel, const struct options *o);
+bool dco_check_startup_option(unsigned int msglevel, const struct options *o);
 
 /**
  * Check whether any of the options pushed by the server is not supported by
@@ -98,7 +98,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_pull_options(int msglevel, const struct options *o);
+bool dco_check_pull_options(unsigned int msglevel, const struct options *o);
 
 /**
  * Initialize the DCO context
@@ -261,7 +261,7 @@
 typedef void *dco_context_t;
 
 static inline bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     return false;
 }
@@ -273,19 +273,19 @@
 }
 
 static inline bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(unsigned int msglevel, const struct options *o)
 {
     return false;
 }
src/openvpn/dco_freebsd.c +1 -1
index 56a774d..cb76211 100644
@@ -663,7 +663,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     struct if_clonereq ifcr;
     char *buf = NULL;
src/openvpn/dco_linux.c +2 -2
index 3b08f33..accd432 100644
@@ -79,7 +79,7 @@
  * @return ID on success, negative error code on error
  */
 static int
-resolve_ovpn_netlink_id(int msglevel)
+resolve_ovpn_netlink_id(unsigned int msglevel)
 {
     int ret;
     struct nl_sock *nl_sock = nl_socket_alloc();
@@ -1204,7 +1204,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0)
     {
src/openvpn/dco_win.c +1 -1
index 1dc5cf8..39a5ab6 100644
@@ -609,7 +609,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(unsigned int msglevel)
 {
     /* try to open device by symbolic name */
     HANDLE h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
src/openvpn/dns.c +1 -1
index 5421004..6455cc9 100644
@@ -200,7 +200,7 @@
 }
 
 bool
-dns_options_verify(int msglevel, const struct dns_options *o)
+dns_options_verify(unsigned int msglevel, const struct dns_options *o)
 {
     const struct dns_server *server = o->servers ? o->servers : o->servers_prepull;
     while (server)
src/openvpn/dns.h +1 -1
index 6d97b40..833b937 100644
@@ -166,7 +166,7 @@
  * @param   o           Pointer to the DNS options to validate
  * @return              True if no error was found
  */
-bool dns_options_verify(int msglevel, const struct dns_options *o);
+bool dns_options_verify(unsigned int msglevel, const struct dns_options *o);
 
 /**
  * Makes a deep copy of the passed DNS options.
src/openvpn/env_set.c +1 -1
index 6c7df8e..487a5e2 100644
@@ -209,7 +209,7 @@
 }
 
 void
-env_set_print(int msglevel, const struct env_set *es)
+env_set_print(unsigned int msglevel, const struct env_set *es)
 {
     if (check_debug_level(msglevel))
     {
src/openvpn/env_set.h +1 -1
index 3973a4e..130de75 100644
@@ -85,7 +85,7 @@
 
 const char *env_set_get(const struct env_set *es, const char *name);
 
-void env_set_print(int msglevel, const struct env_set *es);
+void env_set_print(unsigned int msglevel, const struct env_set *es);
 
 /**
  * Write a struct env_set to a file. Each item on one line.
src/openvpn/error.c +2 -2
index 1b98235..90c0f75 100644
@@ -390,8 +390,8 @@
     bool ret = true;
     if (mute_cutoff > 0 && !(flags & M_NOMUTE))
     {
-        const int mute_level = DECODE_MUTE_LEVEL(flags);
-        if (mute_level > 0 && mute_level == mute_category)
+        const unsigned int mute_level = DECODE_MUTE_LEVEL(flags);
+        if (mute_level == mute_category)
         {
             if (mute_count == mute_cutoff)
             {
src/openvpn/error.h +14 -14
index 8388f82..2ad2c5d 100644
@@ -83,22 +83,22 @@
 
 /* msg() flags */
 
-#define M_DEBUG_LEVEL (0x0F) /* debug level mask */
+#define M_DEBUG_LEVEL (0x0Fu) /* debug level mask */
 
-#define M_FATAL    (1 << 4)  /* exit program */
-#define M_NONFATAL (1 << 5)  /* non-fatal error */
-#define M_WARN     (1 << 6)  /* call syslog with LOG_WARNING */
-#define M_DEBUG    (1 << 7)
+#define M_FATAL    (1u << 4)  /* exit program */
+#define M_NONFATAL (1u << 5)  /* non-fatal error */
+#define M_WARN     (1u << 6)  /* call syslog with LOG_WARNING */
+#define M_DEBUG    (1u << 7)
 
-#define M_ERRNO (1 << 8)         /* show errno description */
+#define M_ERRNO (1u << 8)         /* show errno description */
 
-#define M_NOMUTE       (1 << 11) /* don't do mute processing */
-#define M_NOPREFIX     (1 << 12) /* don't show date/time prefix */
-#define M_USAGE_SMALL  (1 << 13) /* fatal options error, call usage_small */
-#define M_MSG_VIRT_OUT (1 << 14) /* output message through msg_status_output callback */
-#define M_OPTERR       (1 << 15) /* print "Options error:" prefix */
-#define M_NOLF         (1 << 16) /* don't print new line */
-#define M_NOIPREFIX    (1 << 17) /* don't print instance prefix */
+#define M_NOMUTE       (1u << 11) /* don't do mute processing */
+#define M_NOPREFIX     (1u << 12) /* don't show date/time prefix */
+#define M_USAGE_SMALL  (1u << 13) /* fatal options error, call usage_small */
+#define M_MSG_VIRT_OUT (1u << 14) /* output message through msg_status_output callback */
+#define M_OPTERR       (1u << 15) /* print "Options error:" prefix */
+#define M_NOLF         (1u << 16) /* don't print new line */
+#define M_NOIPREFIX    (1u << 17) /* don't print instance prefix */
 
 /* flag combinations which are frequently used */
 #define M_ERR    (M_FATAL | M_ERRNO)
@@ -112,7 +112,7 @@
  * A mute level of 0 is always printed.
  */
 #define MUTE_LEVEL_SHIFT 24
-#define MUTE_LEVEL_MASK  0xFF
+#define MUTE_LEVEL_MASK  0xFFu
 
 #define ENCODE_MUTE_LEVEL(mute_level) (((mute_level) & MUTE_LEVEL_MASK) << MUTE_LEVEL_SHIFT)
 #define DECODE_MUTE_LEVEL(flags)      (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEVEL_MASK)
src/openvpn/forward.c +3 -2
index e82b544..cafd8e75 100644
@@ -373,7 +373,8 @@
 #endif
 
 bool
-send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel)
+send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                   unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     bool stat;
@@ -400,7 +401,7 @@
 }
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, unsigned int msglevel)
 {
     if (c->c2.tls_multi)
     {
src/openvpn/forward.h +3 -2
index 79d0f8b..581eae1 100644
@@ -285,7 +285,7 @@
  * @param str        - The message to be sent
  * @param msglevel   - Message level to use for logging
  */
-bool send_control_channel_string(struct context *c, const char *str, int msglevel);
+bool send_control_channel_string(struct context *c, const char *str, unsigned int msglevel);
 
 /*
  * Send a string to remote over the TLS control channel.
@@ -303,7 +303,8 @@
  * @param msglevel   - Message level to use for logging
  */
 
-bool send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel);
+bool send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                        unsigned int msglevel);
 
 
 /**
src/openvpn/init.c +1 -1
index 24aebc0..e6b3b14 100644
@@ -4282,7 +4282,7 @@
 }
 
 void
-management_show_net_callback(void *arg, const int msglevel)
+management_show_net_callback(void *arg, const unsigned int msglevel)
 {
 #ifdef _WIN32
     show_routes(msglevel);
src/openvpn/init.h +1 -1
index a807874..432cf31 100644
@@ -136,7 +136,7 @@
 
 void close_management(void);
 
-void management_show_net_callback(void *arg, const int msglevel);
+void management_show_net_callback(void *arg, const unsigned int msglevel);
 
 #endif
 
src/openvpn/manage.h +1 -1
index 7c189ba..4b62b04 100644
@@ -176,7 +176,7 @@
     unsigned int flags;
 
     void (*status)(void *arg, const int version, struct status_output *so);
-    void (*show_net)(void *arg, const int msglevel);
+    void (*show_net)(void *arg, const unsigned int msglevel);
     int (*kill_by_cn)(void *arg, const char *common_name);
     int (*kill_by_addr)(void *arg, const in_addr_t addr, const int port, const int proto);
     void (*delete_event)(void *arg, event_t event);
src/openvpn/mtu.c +2 -2
index 1e021e3..f5bc814 100644
@@ -187,7 +187,7 @@
 }
 
 void
-frame_print(const struct frame *frame, int level, const char *prefix)
+frame_print(const struct frame *frame, unsigned int msglevel, const char *prefix)
 {
     struct gc_arena gc = gc_new();
     struct buffer out = alloc_buf_gc(256, &gc);
@@ -208,7 +208,7 @@
     buf_printf(&out, " ET:%d", frame->extra_tun);
     buf_printf(&out, " ]");
 
-    msg(level, "%s", out.data);
+    msg(msglevel, "%s", out.data);
     gc_free(&gc);
 }
 
src/openvpn/mtu.h +1 -1
index c092461..c555f51 100644
@@ -181,7 +181,7 @@
  * Function prototypes.
  */
 
-void frame_print(const struct frame *frame, int level, const char *prefix);
+void frame_print(const struct frame *frame, unsigned int msglevel, const char *prefix);
 
 void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af);
 
src/openvpn/multi.c +1 -1
index 579eeea..a68832b 100644
@@ -3321,7 +3321,7 @@
     }
     else
     {
-        int msglevel = D_DCO;
+        unsigned int msglevel = D_DCO;
         if (dco->dco_message_type == OVPN_CMD_DEL_PEER
             && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
         {
src/openvpn/options.c +52 -48

330 lines not on this page · raw message

src/openvpn/options.h +6 -6
index bb2c052..5e918bb 100644
@@ -822,7 +822,7 @@
     struct pull_filter *tail;
 };
 
-void parse_argv(struct options *options, const int argc, char *argv[], const int msglevel,
+void parse_argv(struct options *options, const int argc, char *argv[], const unsigned int msglevel,
                 const unsigned int permission_mask, unsigned int *option_types_found,
                 struct env_set *es);
 
@@ -888,7 +888,7 @@
 
 void options_detach(struct options *o);
 
-void options_server_import(struct options *o, const char *filename, int msglevel,
+void options_server_import(struct options *o, const char *filename, unsigned int msglevel,
                            unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
@@ -897,13 +897,13 @@
 void rol_check_alloc(struct options *options);
 
 int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num,
-               int msglevel, struct gc_arena *gc);
+               unsigned int msglevel, struct gc_arena *gc);
 
 /*
  * parse/print topology coding
  */
 
-int parse_topology(const char *str, const int msglevel);
+int parse_topology(const char *str, const unsigned int msglevel);
 
 const char *print_topology(const int topology);
 
@@ -917,11 +917,11 @@
 
 int auth_retry_get(void);
 
-bool auth_retry_set(const int msglevel, const char *option);
+bool auth_retry_set(const unsigned int msglevel, const char *option);
 
 const char *auth_retry_print(void);
 
-void options_string_import(struct options *options, const char *config, const int msglevel,
+void options_string_import(struct options *options, const char *config, const unsigned int msglevel,
                            const unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
src/openvpn/options_util.c +5 -4
index a351967..eeaabe1 100644
@@ -117,7 +117,7 @@
 }
 
 int
-positive_atoi(const char *str, int msglevel)
+positive_atoi(const char *str, unsigned int msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -132,7 +132,7 @@
 }
 
 bool
-positive_atoll(const char *str, int64_t *value, const char *name, int msglevel)
+positive_atoll(const char *str, int64_t *value, const char *name, unsigned int msglevel)
 {
     char *endptr;
     long long ll = strtoll(str, &endptr, 10);
@@ -148,7 +148,7 @@
 }
 
 int
-atoi_warn(const char *str, int msglevel)
+atoi_warn(const char *str, unsigned int msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -165,10 +165,11 @@
 #if defined(__GNUC__) || defined(__clang__)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wconversion"
+#pragma GCC diagnostic ignored "-Wsign-conversion"
 #endif
 
 bool
-atoi_constrained(const char *str, int *value, const char *name, int min, int max, int msglevel)
+atoi_constrained(const char *str, int *value, const char *name, int min, int max, unsigned int msglevel)
 {
     ASSERT(min < max);
 
src/openvpn/options_util.h +4 -4
index 45417d9..15a9a28 100644
@@ -37,7 +37,7 @@
  * Converts a str to a positive number if the string represents a postive
  * integer number. Otherwise print a warning with msglevel and return 0
  */
-int positive_atoi(const char *str, int msglevel);
+int positive_atoi(const char *str, unsigned int msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -48,13 +48,13 @@
  *
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
-bool positive_atoll(const char *str, int64_t *value, const char *name, int msglevel);
+bool positive_atoll(const char *str, int64_t *value, const char *name, unsigned int msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
  * integer number. Otherwise print a warning with \p msglevel and return 0
  */
-int atoi_warn(const char *str, int msglevel);
+int atoi_warn(const char *str, unsigned int msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -66,7 +66,7 @@
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
 bool atoi_constrained(const char *str, int *value, const char *name, int min, int max,
-                      int msglevel);
+                      unsigned int msglevel);
 
 /**
  * Filter an option line by all pull filters.
src/openvpn/packet_id.c +5 -4
index 0b33c9c..63a4cae 100644
@@ -53,15 +53,15 @@
 #define SEQ_EXPIRED ((time_t)1)
 
 #ifdef ENABLE_DEBUG
-static void packet_id_debug_print(int msglevel, const struct packet_id_rec *p,
+static void packet_id_debug_print(unsigned int msglevel, const struct packet_id_rec *p,
                                   const struct packet_id_net *pin, const char *message,
                                   packet_id_print_type value);
 
 #endif /* ENABLE_DEBUG */
 
 static inline void
-packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
-                const char *message, uint64_t value)
+packet_id_debug(unsigned int msglevel, const struct packet_id_rec *p,
+                const struct packet_id_net *pin, const char *message, uint64_t value)
 {
 #ifdef ENABLE_DEBUG
     if (unlikely(check_debug_level(msglevel)))
@@ -578,7 +578,8 @@
 #ifdef ENABLE_DEBUG
 
 static void
-packet_id_debug_print(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
+packet_id_debug_print(unsigned int msglevel, const struct packet_id_rec *p,
+                      const struct packet_id_net *pin,
                       const char *message, packet_id_print_type value)
 {
     struct gc_arena gc = gc_new();
src/openvpn/plugin.c +4 -4
index ea76a08..8223a2c 100644
@@ -50,7 +50,7 @@
 static struct plugin_common *static_plugin_common = NULL; /* GLOBAL */
 
 static void
-plugin_show_string_array(int msglevel, const char *name, const char *array[])
+plugin_show_string_array(unsigned int msglevel, const char *name, const char *array[])
 {
     int i;
     for (i = 0; array[i]; ++i)
@@ -63,7 +63,7 @@
 }
 
 static void
-plugin_show_args_env(int msglevel, const char *argv[], const char *envp[])
+plugin_show_args_env(unsigned int msglevel, const char *argv[], const char *envp[])
 {
     if (check_debug_level(msglevel))
     {
@@ -184,7 +184,7 @@
 
 #ifndef ENABLE_SMALL
 void
-plugin_option_list_print(const struct plugin_option_list *list, int msglevel)
+plugin_option_list_print(const struct plugin_option_list *list, unsigned int msglevel)
 {
     int i;
     struct gc_arena gc = gc_new();
@@ -995,7 +995,7 @@
 
 #ifdef ENABLE_DEBUG
 void
-plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr)
+plugin_return_print(const unsigned int msglevel, const char *prefix, const struct plugin_return *pr)
 {
     int i;
     msg(msglevel, "PLUGIN_RETURN_PRINT %s", prefix);
src/openvpn/plugin.h +2 -2
index 63999b6..91d3fba 100644
@@ -111,7 +111,7 @@
 bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc);
 
 #ifndef ENABLE_SMALL
-void plugin_option_list_print(const struct plugin_option_list *list, int msglevel);
+void plugin_option_list_print(const struct plugin_option_list *list, unsigned int msglevel);
 
 #endif
 
@@ -136,7 +136,7 @@
 void plugin_return_free(struct plugin_return *pr);
 
 #ifdef ENABLE_DEBUG
-void plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr);
+void plugin_return_print(const unsigned int msglevel, const char *prefix, const struct plugin_return *pr);
 
 #endif
 
src/openvpn/pool.c +2 -2
index fde6cea..0e95c5e 100644
@@ -114,7 +114,7 @@
  * Verify start/end range
  */
 bool
-ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end)
+ifconfig_pool_verify_range(const unsigned int msglevel, const in_addr_t start, const in_addr_t end)
 {
     struct gc_arena gc = gc_new();
     bool ret = true;
@@ -521,7 +521,7 @@
 }
 
 static void
-ifconfig_pool_msg(const struct ifconfig_pool *pool, int msglevel)
+ifconfig_pool_msg(const struct ifconfig_pool *pool, unsigned int msglevel)
 {
     struct status_output *so = status_open(NULL, 0, msglevel, NULL, 0);
     ASSERT(so);
src/openvpn/pool.h +1 -1
index 6cecef0..9c69512 100644
@@ -78,7 +78,7 @@
 
 void ifconfig_pool_free(struct ifconfig_pool *pool);
 
-bool ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end);
+bool ifconfig_pool_verify_range(const unsigned int msglevel, const in_addr_t start, const in_addr_t end);
 
 ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local,
                                            in_addr_t *remote, struct in6_addr *remote_ipv6,
src/openvpn/push.c +7 -7
index 671b015..d4019e5 100644
@@ -373,8 +373,8 @@
  *
  * @return true on success, false on failure.
  */
-static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel,
-                            const char *fmt, ...)
+static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                            unsigned int msglevel, const char *fmt, ...)
 #ifdef __GNUC__
 #if __USE_MINGW_ANSI_STDIO
     __attribute__((format(gnu_printf, 4, 5)))
@@ -857,7 +857,7 @@
 
 static void
 push_option_ex(struct gc_arena *gc, struct push_list *push_list, const char *opt, bool enable,
-               int msglevel)
+               unsigned int msglevel)
 {
     if (!string_class(opt, CC_ANY, CC_COMMA))
     {
@@ -885,7 +885,7 @@
 }
 
 void
-push_option(struct options *o, const char *opt, int msglevel)
+push_option(struct options *o, const char *opt, unsigned int msglevel)
 {
     push_option_ex(&o->gc, &o->push_list, opt, true, msglevel);
 }
@@ -906,7 +906,7 @@
 }
 
 void
-push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc)
+push_options(struct options *o, char **p, unsigned int msglevel, struct gc_arena *gc)
 {
     const char **argv = make_extended_arg_array(p, false, gc);
     char *opt = print_argv(argv, gc, 0);
@@ -914,8 +914,8 @@
 }
 
 static bool
-push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel, const char *format,
-                ...)
+push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                unsigned int msglevel, const char *format, ...)
 {
     va_list arglist;
     char tmp[256] = { 0 };
src/openvpn/push.h +2 -2
index 8ffd0c2..a13e24f 100644
@@ -99,9 +99,9 @@
 
 void clone_push_list(struct options *o);
 
-void push_option(struct options *o, const char *opt, int msglevel);
+void push_option(struct options *o, const char *opt, unsigned int msglevel);
 
-void push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc);
+void push_options(struct options *o, char **p, unsigned int msglevel, struct gc_arena *gc);
 
 void push_reset(struct options *o);
 
src/openvpn/route.c +13 -13
index d3d2954..72e763d 100644
@@ -1228,28 +1228,28 @@
 }
 
 static void
-print_route_option(const struct route_option *ro, int level)
+print_route_option(const struct route_option *ro, unsigned int msglevel)
 {
-    msg(level, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
+    msg(msglevel, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
         show_opt(ro->gateway), show_opt(ro->metric));
 }
 
 void
-print_route_options(const struct route_option_list *rol, int level)
+print_route_options(const struct route_option_list *rol, unsigned int msglevel)
 {
     struct route_option *ro;
     if (rol->flags & RG_ENABLE)
     {
-        msg(level, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
+        msg(msglevel, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
     }
     for (ro = rol->routes; ro; ro = ro->next)
     {
-        print_route_option(ro, level);
+        print_route_option(ro, msglevel);
     }
 }
 
 void
-print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+print_default_gateway(const unsigned int msglevel, const struct route_gateway_info *rgi,
                       const struct route_ipv6_gateway_info *rgi6)
 {
     struct gc_arena gc = gc_new();
@@ -1323,23 +1323,23 @@
 #endif /* ifndef ENABLE_SMALL */
 
 static void
-print_route(const struct route_ipv4 *r, int level)
+print_route(const struct route_ipv4 *r, unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
     if (r->flags & RT_DEFINED)
     {
-        msg(level, "%s", route_string(r, &gc));
+        msg(msglevel, "%s", route_string(r, &gc));
     }
     gc_free(&gc);
 }
 
 void
-print_routes(const struct route_list *rl, int level)
+print_routes(const struct route_list *rl, unsigned int msglevel)
 {
     struct route_ipv4 *r;
     for (r = rl->routes; r; r = r->next)
     {
-        print_route(r, level);
+        print_route(r, msglevel);
     }
 }
 
@@ -3067,18 +3067,18 @@
  * Show current routing table
  */
 void
-show_routes(int msglev)
+show_routes(unsigned int msglevel)
 {
     struct gc_arena gc = gc_new();
 
     const MIB_IPFORWARDTABLE *rt = get_windows_routing_table(&gc);
 
-    msg(msglev, "SYSTEM ROUTING TABLE");
+    msg(msglevel, "SYSTEM ROUTING TABLE");
     if (rt)
     {
         for (DWORD i = 0; i < rt->dwNumEntries; ++i)
         {
-            msg(msglev, "%s", format_route_entry(&rt->table[i], &gc));
+            msg(msglevel, "%s", format_route_entry(&rt->table[i], &gc));
         }
     }
     gc_free(&gc);
src/openvpn/route.h +4 -4
index 9b6a47e..b8c8244 100644
@@ -356,7 +356,7 @@
 void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi, const struct in6_addr *dest,
                               openvpn_net_ctx_t *ctx);
 
-void print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+void print_default_gateway(const unsigned int msglevel, const struct route_gateway_info *rgi,
                            const struct route_ipv6_gateway_info *rgi6);
 
 /*
@@ -371,15 +371,15 @@
 int test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi);
 
 #ifndef ENABLE_SMALL
-void print_route_options(const struct route_option_list *rol, int level);
+void print_route_options(const struct route_option_list *rol, unsigned int msglevel);
 
 #endif
 
-void print_routes(const struct route_list *rl, int level);
+void print_routes(const struct route_list *rl, unsigned int msglevel);
 
 #ifdef _WIN32
 
-void show_routes(int msglev);
+void show_routes(unsigned int msglevel);
 
 bool test_routes(const struct route_list *rl, const struct tuntap *tt);
 
src/openvpn/run_command.c +1 -1
index 4a1ef22..942434c 100644
@@ -107,7 +107,7 @@
 
 #ifndef WIN32
 bool
-openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel)
+openvpn_waitpid_check(pid_t pid, const char *msg_prefix, unsigned int msglevel)
 {
     if (pid == 0)
     {
src/openvpn/run_command.h +5 -5
index afd1b88..222272c 100644
@@ -71,13 +71,13 @@
  * This function is currently not implemented for Windows as the helper
  * macros used by this function are not available.
  *
- * @param pid               pid of the process to be checked
+ * @param pid            pid of the process to be checked
  * @param msg_prefix     prefixed of the message that be printed
- * @param msglevel          msglevel of the messages to be printed
- * @return                  true if the process is still running, false if
- *                          an error condition occurred
+ * @param msglevel       msglevel of the messages to be printed
+ * @return               true if the process is still running, false if
+ *                       an error condition occurred
  */
-bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel);
+bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, unsigned int msglevel);
 
 #endif
 
src/openvpn/sig.c +1 -1
index ecea635..35c2249 100644
@@ -287,7 +287,7 @@
 }
 
 void
-print_signal(const struct signal_info *si, const char *title, int msglevel)
+print_signal(const struct signal_info *si, const char *title, unsigned int msglevel)
 {
     if (si)
     {
src/openvpn/sig.h +1 -1
index 7e5dd9f..06558d7 100644
@@ -66,7 +66,7 @@
 
 void restore_signal_state(void);
 
-void print_signal(const struct signal_info *si, const char *title, int msglevel);
+void print_signal(const struct signal_info *si, const char *title, unsigned int msglevel);
 
 void print_status(struct context *c, struct status_output *so);
 
src/openvpn/socket.c +4 -3
index 248c690..6f73514 100644
@@ -83,7 +83,7 @@
 static int
 get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname, void *network,
                  unsigned int *netbits, int resolve_retry_seconds, struct signal_info *sig_info,
-                 int msglevel)
+                 unsigned int msglevel)
 {
     char *endp, *sep, *var_host = NULL;
     struct addrinfo *ai = NULL;
@@ -216,7 +216,8 @@
 }
 
 bool
-get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
+get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
+              unsigned int msglevel)
 {
     if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostname, network, netbits, 0, NULL, msglevel)
         < 0)
@@ -1521,7 +1522,7 @@
 linksock_print_addr(struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
-    const int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
+    const unsigned int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
 
     /* print local address */
     if (sock->bind_local)
src/openvpn/socket_util.c +3 -3
index 9b7312d..454b151 100644
@@ -541,7 +541,7 @@
     struct addrinfo hints;
     int status;
     struct signal_info sigrec = { 0 };
-    int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
+    unsigned int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
     struct gc_arena gc = gc_new();
     const char *print_hostname;
     const char *print_servname;
@@ -604,7 +604,7 @@
         int resolve_retries =
             (flags & GETADDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) / fail_wait_interval);
         const char *fmt;
-        int level = 0;
+        unsigned int level = 0;
 
         /* this is not a numeric IP, therefore force resolution using the
          * provided ai_family */
@@ -739,7 +739,7 @@
 done:
     if (sig_info && sig_info->signal_received)
     {
-        int level = 0;
+        unsigned int level = 0;
         if (flags & GETADDR_FATAL_ON_SIGNAL)
         {
             level = M_FATAL;
src/openvpn/socket_util.h +1 -1
index 361edff..8a30527 100644
@@ -142,7 +142,7 @@
  * Translate an IPv6 addr or hostname from string form to in6_addr
  */
 bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
-                   int msglevel);
+                   unsigned int msglevel);
 
 int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname,
                         int resolve_retry_seconds, struct signal_info *sig_info, int ai_family,
src/openvpn/ssl_verify_backend.h +2 -2
index a0559c9..af7a08f 100644
@@ -193,8 +193,8 @@
  * @param gc            Garbage collection arena for temp data
  *
  */
-void x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
-                    struct gc_arena *gc);
+void x509_track_add(const struct x509_track **ll_head, const char *name,
+                    unsigned int msglevel, struct gc_arena *gc);
 
 /*
  * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_mbedtls.c +1 -1
index a2c702d..2ea410d 100644
@@ -359,7 +359,7 @@
 }
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, unsigned int msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/ssl_verify_openssl.c +1 -1
index 122101c..e3c18a4 100644
@@ -414,7 +414,7 @@
  */
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, unsigned int msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/status.c +2 -3
index fbd2168..a9f9498 100644
@@ -235,14 +235,13 @@
 
         if (so->msglevel >= 0 && !so->errors)
         {
-            msg(so->msglevel, "%s", buf);
+            msg((unsigned int)so->msglevel, "%s", buf);
         }
 
         if (so->fd >= 0 && !so->errors)
         {
-            int len;
             strcat(buf, "\n");
-            len = strlen(buf);
+            size_t len = strlen(buf);
             if (len > 0)
             {
                 if (write(so->fd, buf, len) != len)
src/openvpn/status.h +1 -0
index 0c7a869..25e1663 100644
@@ -53,6 +53,7 @@
 
     char *filename;
     int fd;
+    /* NB: -1 is used to indicate that output should only go to the file */
     int msglevel;
     const struct virtual_output *vout;
 
src/openvpn/tun.c +27 -27

146 lines not on this page · raw message

src/openvpn/tun.h +2 -2
index 06fc729..fd2d270 100644
@@ -445,9 +445,9 @@
 DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count,
                           in_addr_t *netmask);
 
-void show_tap_win_adapters(int msglev, int warnlev);
+void show_tap_win_adapters(unsigned int msglevel, unsigned int warnlevel);
 
-void show_adapters(int msglev);
+void show_adapters(unsigned int msglevel);
 
 void tap_allow_nonadmin_access(const char *dev_node);
 
tests/unit_tests/openvpn/mock_ssl_dependencies.c +1 -1
index 7333c47..3abab43 100644
@@ -38,7 +38,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_argv.c +1 -1
index a65857b..a4f9e84 100644
@@ -23,7 +23,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  unsigned int msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_misc.c +1 -1
index 3433b73..5348e53 100644
@@ -348,7 +348,7 @@
     assert_false(valid_integer("-2147483653", false));
 
 
-    int msglevel = D_LOW;
+    unsigned int msglevel = D_LOW;
     int saved_log_level = mock_get_debug_level();
     mock_set_debug_level(D_LOW);
 
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
index 9ba6cfc..1519fd6 100644
@@ -59,7 +59,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_pkt.c +1 -1
index 5122766..f349824 100644
@@ -45,7 +45,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_push_update_msg.c +2 -2
index 87329b1..8948f7b 100644
@@ -111,7 +111,7 @@
 
 #ifndef ENABLE_MANAGEMENT
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, unsigned int msglevel)
 {
     return true;
 }
@@ -120,7 +120,7 @@
 int i;
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, unsigned int msglevel)
 {
     if (res && res[i] && strcmp(res[i], str))
     {
tests/unit_tests/openvpn/test_tls_crypt.c +1 -1
index 532bfcd..e2b2e38 100644
@@ -98,7 +98,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  unsigned int msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_user_pass.c +1 -1
index 460b37f..30b0a73 100644
@@ -73,7 +73,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           unsigned int msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 14
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-MessageType: newpatchset

#9 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: Introduce msglvl_t to unify msglevel type handling

In reply to a message not in the archive

Attention is currently required from: cron2, plaisthos.

Hello cron2, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email

to look at the new patch set (#15).

Change subject: Introduce msglvl_t to unify msglevel type handling
......................................................................

Introduce msglvl_t to unify msglevel type handling

msglevel was definitely unsigned as the first
argument to msg(), but many parts of the code
had it as signed. So this produced a LOT of
warnings when enabling -Wsign-conversion.

Introduce a msglvl_t typedef and switch all
users to it. This includes any values that
are stored in the msglevel field, including
debug level and mute level.

There is one exception in struct status_output
where -1 is a valid value in the API. Only
positive values are translated into standard
message levels.

Change-Id Id492cb774c6d022d06bb3cf5fec2a4bdd410e619

---
M src/openvpn/argv.c
M src/openvpn/argv.h
M src/openvpn/buffer.c
M src/openvpn/clinat.c
M src/openvpn/clinat.h
M src/openvpn/comp.c
M src/openvpn/comp.h
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/dco.c
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dns.c
M src/openvpn/dns.h
M src/openvpn/env_set.c
M src/openvpn/env_set.h
M src/openvpn/error.c
M src/openvpn/error.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/manage.c
M src/openvpn/manage.h
M src/openvpn/mtu.c
M src/openvpn/mtu.h
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/packet_id.c
M src/openvpn/pkcs11.c
M src/openvpn/plugin.c
M src/openvpn/plugin.h
M src/openvpn/pool.c
M src/openvpn/pool.h
M src/openvpn/proto.c
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/sig.c
M src/openvpn/sig.h
M src/openvpn/socket.c
M src/openvpn/socket_util.c
M src/openvpn/socket_util.h
M src/openvpn/ssl_verify_backend.h
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/status.c
M src/openvpn/status.h
M src/openvpn/tun.c
M src/openvpn/tun.h
M tests/unit_tests/openvpn/mock_msg.c
M tests/unit_tests/openvpn/mock_msg.h
M tests/unit_tests/openvpn/mock_ssl_dependencies.c M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_push_update_msg.c M tests/unit_tests/openvpn/test_socket.c
M tests/unit_tests/openvpn/test_tls_crypt.c M tests/unit_tests/openvpn/test_user_pass.c

69 files changed, 285 insertions(+), 276 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/1110/15

src/openvpn/argv.c +9 -9
index 903fc0a..79b541a 100644
@@ -235,14 +235,14 @@
 /**
  *  Write the arguments stored in a struct argv via the msg() command.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write.
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write.
  */
 void
-argv_msg(const int msglev, const struct argv *a)
+argv_msg(const msglvl_t msglevel, const struct argv *a)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s", argv_str(a, &gc, 0));
+    msg(msglevel, "%s", argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
@@ -250,16 +250,16 @@
  *  Similar to argv_msg() but prefixes the messages being written with a
  *  given string.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write
- *  @param prefix  Valid pointer to the prefix string
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write
+ *  @param prefix    Valid pointer to the prefix string
  *
  */
 void
-argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix)
+argv_msg_prefix(const msglvl_t msglevel, const struct argv *a, const char *prefix)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s: %s", prefix, argv_str(a, &gc, 0));
+    msg(msglevel, "%s: %s", prefix, argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
src/openvpn/argv.h +2 -2
index 056fe31..969d7b1 100644
@@ -47,9 +47,9 @@
 
 struct argv argv_insert_head(const struct argv *a, const char *head);
 
-void argv_msg(const int msglev, const struct argv *a);
+void argv_msg(const msglvl_t msglevel, const struct argv *a);
 
-void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix);
+void argv_msg_prefix(const msglvl_t msglevel, const struct argv *a, const char *prefix);
 
 void argv_parse_cmd(struct argv *a, const char *s);
 
src/openvpn/buffer.c +1 -1
index 0f0d17e..c0b85b2 100644
@@ -1127,7 +1127,7 @@
 {
     if (buf && buf->len)
     {
-        int msglevel = D_ALIGN_DEBUG;
+        msglvl_t msglevel = D_ALIGN_DEBUG;
         const unsigned int u = (unsigned int)BPTR(buf);
 
         if (u & (PAYLOAD_ALIGN - 1))
src/openvpn/clinat.c +3 -3
index 48a2057..b49d4bb 100644
@@ -47,7 +47,7 @@
 }
 
 void
-print_client_nat_list(const struct client_nat_option_list *list, int msglevel)
+print_client_nat_list(const struct client_nat_option_list *list, msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     int i;
@@ -101,7 +101,7 @@
 void
 add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                               const char *network, const char *netmask, const char *foreign_network,
-                              int msglevel)
+                              msglvl_t msglevel)
 {
     struct client_nat_entry e;
     bool ok;
@@ -159,7 +159,7 @@
 #endif
 
 static void
-print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const int msglevel)
+print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
 
src/openvpn/clinat.h +2 -2
index abfa0b7..7d787e0 100644
@@ -54,11 +54,11 @@
 void copy_client_nat_option_list(struct client_nat_option_list *dest,
                                  const struct client_nat_option_list *src);
 
-void print_client_nat_list(const struct client_nat_option_list *list, int msglevel);
+void print_client_nat_list(const struct client_nat_option_list *list, msglvl_t msglevel);
 
 void add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                                    const char *network, const char *netmask,
-                                   const char *foreign_network, int msglevel);
+                                   const char *foreign_network, msglvl_t msglevel);
 
 void client_nat_transform(const struct client_nat_option_list *list, struct buffer *ipbuf,
                           const int direction);
src/openvpn/comp.c +1 -1
index 1a2e775..9d35141 100644
@@ -159,7 +159,7 @@
 #endif /* USE_COMP */
 
 bool
-check_compression_settings_valid(struct compress_options *info, int msglevel)
+check_compression_settings_valid(struct compress_options *info, msglvl_t msglevel)
 {
     /*
      * We also allow comp-stub-v2 here as it technically allows escaping of
src/openvpn/comp.h +3 -1
index 0354896..1717029 100644
@@ -84,12 +84,14 @@
            && info->alg != COMP_ALG_UNDEF;
 }
 
+#include "error.h"
+
 /**
  * Checks if the compression settings are valid. Takes into account the
  * flags of allow-compression and also the whether algorithms are compiled
  * in
  */
-bool check_compression_settings_valid(struct compress_options *info, int msglevel);
+bool check_compression_settings_valid(struct compress_options *info, msglvl_t msglevel);
 
 #ifdef USE_COMP
 #include "buffer.h"
src/openvpn/crypto.c +1 -1
index 1535c78..0e930d6 100644
@@ -1618,7 +1618,7 @@
 }
 
 int
-ascii2keydirection(int msglevel, const char *str)
+ascii2keydirection(msglvl_t msglevel, const char *str)
 {
     if (!str)
     {
src/openvpn/crypto.h +1 -1
index efd7f60..d69db59 100644
@@ -618,7 +618,7 @@
 
 void must_have_n_keys(const char *filename, const char *option, const struct key2 *key2, int n);
 
-int ascii2keydirection(int msglevel, const char *str);
+int ascii2keydirection(msglvl_t msglevel, const char *str);
 
 const char *keydirection2ascii(int kd, bool remote, bool humanreadable);
 
src/openvpn/dco.c +4 -4
index 823b4f9..2cf90af 100644
@@ -233,7 +233,7 @@
 }
 
 static bool
-dco_check_option_ce(const struct connection_entry *ce, int msglevel, int mode)
+dco_check_option_ce(const struct connection_entry *ce, msglvl_t msglevel, int mode)
 {
     if (ce->fragment)
     {
@@ -293,7 +293,7 @@
 }
 
 bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(msglvl_t msglevel, const struct options *o)
 {
     /* check if no dev name was specified at all. In the case,
      * later logic will most likely stop OpenVPN, so no need to
@@ -430,7 +430,7 @@
 }
 
 bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(msglvl_t msglevel, const struct options *o)
 {
     /* At this point the ciphers have already been normalised */
     if (o->enable_ncp_fallback
@@ -480,7 +480,7 @@
 }
 
 bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(msglvl_t msglevel, const struct options *o)
 {
     if (!o->use_peer_id)
     {
src/openvpn/dco.h +8 -8
index 59acb18..a362977 100644
@@ -55,7 +55,7 @@
  * @param msglevel      level to print messages to
  * @return              true if ovpn-dco is available, false otherwise
  */
-bool dco_available(int msglevel);
+bool dco_available(msglvl_t msglevel);
 
 
 /**
@@ -75,7 +75,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_option(int msglevel, const struct options *o);
+bool dco_check_option(msglvl_t msglevel, const struct options *o);
 
 /**
  * Check whether the options struct has any further option that is not supported
@@ -87,7 +87,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_startup_option(int msglevel, const struct options *o);
+bool dco_check_startup_option(msglvl_t msglevel, const struct options *o);
 
 /**
  * Check whether any of the options pushed by the server is not supported by
@@ -98,7 +98,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_pull_options(int msglevel, const struct options *o);
+bool dco_check_pull_options(msglvl_t msglevel, const struct options *o);
 
 /**
  * Initialize the DCO context
@@ -261,7 +261,7 @@
 typedef void *dco_context_t;
 
 static inline bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     return false;
 }
@@ -273,19 +273,19 @@
 }
 
 static inline bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
src/openvpn/dco_freebsd.c +1 -1
index 56a774d..b9f6bc7 100644
@@ -663,7 +663,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     struct if_clonereq ifcr;
     char *buf = NULL;
src/openvpn/dco_linux.c +2 -2
index 3b08f33..395a38f 100644
@@ -79,7 +79,7 @@
  * @return ID on success, negative error code on error
  */
 static int
-resolve_ovpn_netlink_id(int msglevel)
+resolve_ovpn_netlink_id(msglvl_t msglevel)
 {
     int ret;
     struct nl_sock *nl_sock = nl_socket_alloc();
@@ -1204,7 +1204,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0)
     {
src/openvpn/dco_win.c +1 -1
index 1dc5cf8..9e52859 100644
@@ -609,7 +609,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     /* try to open device by symbolic name */
     HANDLE h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
src/openvpn/dns.c +1 -1
index 5421004..efb888a 100644
@@ -200,7 +200,7 @@
 }
 
 bool
-dns_options_verify(int msglevel, const struct dns_options *o)
+dns_options_verify(msglvl_t msglevel, const struct dns_options *o)
 {
     const struct dns_server *server = o->servers ? o->servers : o->servers_prepull;
     while (server)
src/openvpn/dns.h +1 -1
index 6d97b40..6cd98f2 100644
@@ -166,7 +166,7 @@
  * @param   o           Pointer to the DNS options to validate
  * @return              True if no error was found
  */
-bool dns_options_verify(int msglevel, const struct dns_options *o);
+bool dns_options_verify(msglvl_t msglevel, const struct dns_options *o);
 
 /**
  * Makes a deep copy of the passed DNS options.
src/openvpn/env_set.c +1 -1
index 6c7df8e..2ae71ab 100644
@@ -209,7 +209,7 @@
 }
 
 void
-env_set_print(int msglevel, const struct env_set *es)
+env_set_print(msglvl_t msglevel, const struct env_set *es)
 {
     if (check_debug_level(msglevel))
     {
src/openvpn/env_set.h +1 -1
index 3973a4e..ddcfa14 100644
@@ -85,7 +85,7 @@
 
 const char *env_set_get(const struct env_set *es, const char *name);
 
-void env_set_print(int msglevel, const struct env_set *es);
+void env_set_print(msglvl_t msglevel, const struct env_set *es);
 
 /**
  * Write a struct env_set to a file. Each item on one line.
src/openvpn/error.c +15 -17
index 1b98235..58c2fd1 100644
@@ -48,12 +48,12 @@
 #endif
 
 /* Globals */
-unsigned int x_debug_level; /* GLOBAL */
+msglvl_t x_debug_level; /* GLOBAL */
 
 /* Mute state */
-static int mute_cutoff;   /* GLOBAL */
-static int mute_count;    /* GLOBAL */
-static int mute_category; /* GLOBAL */
+static int mute_cutoff;        /* GLOBAL */
+static int mute_count;         /* GLOBAL */
+static msglvl_t mute_category; /* GLOBAL */
 
 /*
  * Output mode priorities are as follows:
@@ -103,16 +103,14 @@
 bool
 set_debug_level(const int level, const unsigned int flags)
 {
-    const int ceiling = 15;
-
-    if (level >= 0 && level <= ceiling)
+    if (level >= 0 && level <= M_DEBUG_LEVEL)
     {
-        x_debug_level = level;
+        x_debug_level = (msglvl_t)level;
         return true;
     }
     else if (flags & SDL_CONSTRAIN)
     {
-        x_debug_level = constrain_int(level, 0, ceiling);
+        x_debug_level = (msglvl_t)constrain_int(level, 0, M_DEBUG_LEVEL);
         return true;
     }
     return false;
@@ -132,7 +130,7 @@
     }
 }
 
-int
+msglvl_t
 get_debug_level(void)
 {
     return x_debug_level;
@@ -190,7 +188,7 @@
  * Return a file to print messages to before syslog is opened.
  */
 FILE *
-msg_fp(const unsigned int flags)
+msg_fp(const msglvl_t flags)
 {
     FILE *fp = msgfp;
     if (!fp)
@@ -214,7 +212,7 @@
 int x_msg_line_num; /* GLOBAL */
 
 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const msglvl_t flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -235,7 +233,7 @@
 }
 
 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const msglvl_t flags, const char *format, va_list arglist)
 {
     struct gc_arena gc;
 #if SYSLOG_CAPABILITY
@@ -385,13 +383,13 @@
  * Apply muting filter.
  */
 bool
-dont_mute(unsigned int flags)
+dont_mute(msglvl_t flags)
 {
     bool ret = true;
     if (mute_cutoff > 0 && !(flags & M_NOMUTE))
     {
-        const int mute_level = DECODE_MUTE_LEVEL(flags);
-        if (mute_level > 0 && mute_level == mute_category)
+        const msglvl_t mute_level = DECODE_MUTE_LEVEL(flags);
+        if (mute_level == mute_category)
         {
             if (mute_count == mute_cutoff)
             {
@@ -750,7 +748,7 @@
  * Translate msg flags into a string
  */
 const char *
-msg_flags_string(const unsigned int flags, struct gc_arena *gc)
+msg_flags_string(const msglvl_t flags, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(16, gc);
     if (flags == M_INFO)
src/openvpn/error.h +27 -25

124 lines not on this page · raw message

src/openvpn/forward.c +3 -2
index e82b544..f342958 100644
@@ -373,7 +373,8 @@
 #endif
 
 bool
-send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel)
+send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                   msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     bool stat;
@@ -400,7 +401,7 @@
 }
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     if (c->c2.tls_multi)
     {
src/openvpn/forward.h +3 -2
index 79d0f8b..a575faf 100644
@@ -285,7 +285,7 @@
  * @param str        - The message to be sent
  * @param msglevel   - Message level to use for logging
  */
-bool send_control_channel_string(struct context *c, const char *str, int msglevel);
+bool send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel);
 
 /*
  * Send a string to remote over the TLS control channel.
@@ -303,7 +303,8 @@
  * @param msglevel   - Message level to use for logging
  */
 
-bool send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel);
+bool send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                        msglvl_t msglevel);
 
 
 /**
src/openvpn/init.c +1 -1
index 24aebc0..f8a0fee 100644
@@ -4282,7 +4282,7 @@
 }
 
 void
-management_show_net_callback(void *arg, const int msglevel)
+management_show_net_callback(void *arg, const msglvl_t msglevel)
 {
 #ifdef _WIN32
     show_routes(msglevel);
src/openvpn/init.h +1 -1
index a807874..e89615b 100644
@@ -136,7 +136,7 @@
 
 void close_management(void);
 
-void management_show_net_callback(void *arg, const int msglevel);
+void management_show_net_callback(void *arg, const msglvl_t msglevel);
 
 #endif
 
src/openvpn/manage.c +1 -1
index 4f37bd2..5a41a0f 100644
@@ -1484,7 +1484,7 @@
         }
         else
         {
-            msg(M_CLIENT, "SUCCESS: verb=%d", get_debug_level());
+            msg(M_CLIENT, "SUCCESS: verb=%u", get_debug_level());
         }
     }
     else if (streq(p[0], "mute"))
src/openvpn/manage.h +1 -1
index 7c189ba..bff96d3 100644
@@ -176,7 +176,7 @@
     unsigned int flags;
 
     void (*status)(void *arg, const int version, struct status_output *so);
-    void (*show_net)(void *arg, const int msglevel);
+    void (*show_net)(void *arg, const msglvl_t msglevel);
     int (*kill_by_cn)(void *arg, const char *common_name);
     int (*kill_by_addr)(void *arg, const in_addr_t addr, const int port, const int proto);
     void (*delete_event)(void *arg, event_t event);
src/openvpn/mtu.c +2 -2
index 1e021e3..66f81a6 100644
@@ -187,7 +187,7 @@
 }
 
 void
-frame_print(const struct frame *frame, int level, const char *prefix)
+frame_print(const struct frame *frame, msglvl_t msglevel, const char *prefix)
 {
     struct gc_arena gc = gc_new();
     struct buffer out = alloc_buf_gc(256, &gc);
@@ -208,7 +208,7 @@
     buf_printf(&out, " ET:%d", frame->extra_tun);
     buf_printf(&out, " ]");
 
-    msg(level, "%s", out.data);
+    msg(msglevel, "%s", out.data);
     gc_free(&gc);
 }
 
src/openvpn/mtu.h +1 -1
index c092461..3bbff6f 100644
@@ -181,7 +181,7 @@
  * Function prototypes.
  */
 
-void frame_print(const struct frame *frame, int level, const char *prefix);
+void frame_print(const struct frame *frame, msglvl_t msglevel, const char *prefix);
 
 void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af);
 
src/openvpn/multi.c +1 -1
index 579eeea..3877f8d 100644
@@ -3321,7 +3321,7 @@
     }
     else
     {
-        int msglevel = D_DCO;
+        msglvl_t msglevel = D_DCO;
         if (dco->dco_message_type == OVPN_CMD_DEL_PEER
             && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
         {
src/openvpn/options.c +52 -48

330 lines not on this page · raw message

src/openvpn/options.h +6 -6
index bb2c052..a737711 100644
@@ -822,7 +822,7 @@
     struct pull_filter *tail;
 };
 
-void parse_argv(struct options *options, const int argc, char *argv[], const int msglevel,
+void parse_argv(struct options *options, const int argc, char *argv[], const msglvl_t msglevel,
                 const unsigned int permission_mask, unsigned int *option_types_found,
                 struct env_set *es);
 
@@ -888,7 +888,7 @@
 
 void options_detach(struct options *o);
 
-void options_server_import(struct options *o, const char *filename, int msglevel,
+void options_server_import(struct options *o, const char *filename, msglvl_t msglevel,
                            unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
@@ -897,13 +897,13 @@
 void rol_check_alloc(struct options *options);
 
 int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num,
-               int msglevel, struct gc_arena *gc);
+               msglvl_t msglevel, struct gc_arena *gc);
 
 /*
  * parse/print topology coding
  */
 
-int parse_topology(const char *str, const int msglevel);
+int parse_topology(const char *str, const msglvl_t msglevel);
 
 const char *print_topology(const int topology);
 
@@ -917,11 +917,11 @@
 
 int auth_retry_get(void);
 
-bool auth_retry_set(const int msglevel, const char *option);
+bool auth_retry_set(const msglvl_t msglevel, const char *option);
 
 const char *auth_retry_print(void);
 
-void options_string_import(struct options *options, const char *config, const int msglevel,
+void options_string_import(struct options *options, const char *config, const msglvl_t msglevel,
                            const unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
src/openvpn/options_util.c +5 -4
index a351967..2928704 100644
@@ -117,7 +117,7 @@
 }
 
 int
-positive_atoi(const char *str, int msglevel)
+positive_atoi(const char *str, msglvl_t msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -132,7 +132,7 @@
 }
 
 bool
-positive_atoll(const char *str, int64_t *value, const char *name, int msglevel)
+positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel)
 {
     char *endptr;
     long long ll = strtoll(str, &endptr, 10);
@@ -148,7 +148,7 @@
 }
 
 int
-atoi_warn(const char *str, int msglevel)
+atoi_warn(const char *str, msglvl_t msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -165,10 +165,11 @@
 #if defined(__GNUC__) || defined(__clang__)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wconversion"
+#pragma GCC diagnostic ignored "-Wsign-conversion"
 #endif
 
 bool
-atoi_constrained(const char *str, int *value, const char *name, int min, int max, int msglevel)
+atoi_constrained(const char *str, int *value, const char *name, int min, int max, msglvl_t msglevel)
 {
     ASSERT(min < max);
 
src/openvpn/options_util.h +4 -4
index 45417d9..1492eef 100644
@@ -37,7 +37,7 @@
  * Converts a str to a positive number if the string represents a postive
  * integer number. Otherwise print a warning with msglevel and return 0
  */
-int positive_atoi(const char *str, int msglevel);
+int positive_atoi(const char *str, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -48,13 +48,13 @@
  *
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
-bool positive_atoll(const char *str, int64_t *value, const char *name, int msglevel);
+bool positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
  * integer number. Otherwise print a warning with \p msglevel and return 0
  */
-int atoi_warn(const char *str, int msglevel);
+int atoi_warn(const char *str, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -66,7 +66,7 @@
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
 bool atoi_constrained(const char *str, int *value, const char *name, int min, int max,
-                      int msglevel);
+                      msglvl_t msglevel);
 
 /**
  * Filter an option line by all pull filters.
src/openvpn/packet_id.c +5 -4
index 0b33c9c..880eee1 100644
@@ -53,15 +53,15 @@
 #define SEQ_EXPIRED ((time_t)1)
 
 #ifdef ENABLE_DEBUG
-static void packet_id_debug_print(int msglevel, const struct packet_id_rec *p,
+static void packet_id_debug_print(msglvl_t msglevel, const struct packet_id_rec *p,
                                   const struct packet_id_net *pin, const char *message,
                                   packet_id_print_type value);
 
 #endif /* ENABLE_DEBUG */
 
 static inline void
-packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
-                const char *message, uint64_t value)
+packet_id_debug(msglvl_t msglevel, const struct packet_id_rec *p,
+                const struct packet_id_net *pin, const char *message, uint64_t value)
 {
 #ifdef ENABLE_DEBUG
     if (unlikely(check_debug_level(msglevel)))
@@ -578,7 +578,8 @@
 #ifdef ENABLE_DEBUG
 
 static void
-packet_id_debug_print(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
+packet_id_debug_print(msglvl_t msglevel, const struct packet_id_rec *p,
+                      const struct packet_id_net *pin,
                       const char *message, packet_id_print_type value)
 {
     struct gc_arena gc = gc_new();
src/openvpn/pkcs11.c +3 -3
index d9c16d9..16149ca 100644
@@ -77,10 +77,10 @@
 #endif
 };
 
-static unsigned
+static msglvl_t
 _pkcs11_msg_pkcs112openvpn(const unsigned flags)
 {
-    unsigned openvpn_flags;
+    msglvl_t openvpn_flags;
 
     switch (flags)
     {
@@ -117,7 +117,7 @@
 }
 
 static unsigned
-_pkcs11_msg_openvpn2pkcs11(const unsigned flags)
+_pkcs11_msg_openvpn2pkcs11(const msglvl_t flags)
 {
     unsigned pkcs11_flags;
 
src/openvpn/plugin.c +4 -4
index ea76a08..a105058 100644
@@ -50,7 +50,7 @@
 static struct plugin_common *static_plugin_common = NULL; /* GLOBAL */
 
 static void
-plugin_show_string_array(int msglevel, const char *name, const char *array[])
+plugin_show_string_array(msglvl_t msglevel, const char *name, const char *array[])
 {
     int i;
     for (i = 0; array[i]; ++i)
@@ -63,7 +63,7 @@
 }
 
 static void
-plugin_show_args_env(int msglevel, const char *argv[], const char *envp[])
+plugin_show_args_env(msglvl_t msglevel, const char *argv[], const char *envp[])
 {
     if (check_debug_level(msglevel))
     {
@@ -184,7 +184,7 @@
 
 #ifndef ENABLE_SMALL
 void
-plugin_option_list_print(const struct plugin_option_list *list, int msglevel)
+plugin_option_list_print(const struct plugin_option_list *list, msglvl_t msglevel)
 {
     int i;
     struct gc_arena gc = gc_new();
@@ -995,7 +995,7 @@
 
 #ifdef ENABLE_DEBUG
 void
-plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr)
+plugin_return_print(const msglvl_t msglevel, const char *prefix, const struct plugin_return *pr)
 {
     int i;
     msg(msglevel, "PLUGIN_RETURN_PRINT %s", prefix);
src/openvpn/plugin.h +2 -2
index 63999b6..81d3739 100644
@@ -111,7 +111,7 @@
 bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc);
 
 #ifndef ENABLE_SMALL
-void plugin_option_list_print(const struct plugin_option_list *list, int msglevel);
+void plugin_option_list_print(const struct plugin_option_list *list, msglvl_t msglevel);
 
 #endif
 
@@ -136,7 +136,7 @@
 void plugin_return_free(struct plugin_return *pr);
 
 #ifdef ENABLE_DEBUG
-void plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr);
+void plugin_return_print(const msglvl_t msglevel, const char *prefix, const struct plugin_return *pr);
 
 #endif
 
src/openvpn/pool.c +2 -2
index fde6cea..2e25ff3 100644
@@ -114,7 +114,7 @@
  * Verify start/end range
  */
 bool
-ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end)
+ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end)
 {
     struct gc_arena gc = gc_new();
     bool ret = true;
@@ -521,7 +521,7 @@
 }
 
 static void
-ifconfig_pool_msg(const struct ifconfig_pool *pool, int msglevel)
+ifconfig_pool_msg(const struct ifconfig_pool *pool, msglvl_t msglevel)
 {
     struct status_output *so = status_open(NULL, 0, msglevel, NULL, 0);
     ASSERT(so);
src/openvpn/pool.h +1 -1
index 6cecef0..36e9fca 100644
@@ -78,7 +78,7 @@
 
 void ifconfig_pool_free(struct ifconfig_pool *pool);
 
-bool ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end);
+bool ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end);
 
 ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local,
                                            in_addr_t *remote, struct in6_addr *remote_ipv6,
src/openvpn/proto.c +1 -1
index 34b3378..ab77887 100644
@@ -183,7 +183,7 @@
             int hlen;
             int totlen;
             const char *msgstr = "PACKET SIZE INFO";
-            unsigned int msglevel = D_PACKET_TRUNC_DEBUG;
+            msglvl_t msglevel = D_PACKET_TRUNC_DEBUG;
 
             if (BLEN(&buf) < (int)sizeof(struct openvpn_iphdr))
             {
src/openvpn/push.c +7 -7
index 671b015..e7fc50c 100644
@@ -373,8 +373,8 @@
  *
  * @return true on success, false on failure.
  */
-static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel,
-                            const char *fmt, ...)
+static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                            msglvl_t msglevel, const char *fmt, ...)
 #ifdef __GNUC__
 #if __USE_MINGW_ANSI_STDIO
     __attribute__((format(gnu_printf, 4, 5)))
@@ -857,7 +857,7 @@
 
 static void
 push_option_ex(struct gc_arena *gc, struct push_list *push_list, const char *opt, bool enable,
-               int msglevel)
+               msglvl_t msglevel)
 {
     if (!string_class(opt, CC_ANY, CC_COMMA))
     {
@@ -885,7 +885,7 @@
 }
 
 void
-push_option(struct options *o, const char *opt, int msglevel)
+push_option(struct options *o, const char *opt, msglvl_t msglevel)
 {
     push_option_ex(&o->gc, &o->push_list, opt, true, msglevel);
 }
@@ -906,7 +906,7 @@
 }
 
 void
-push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc)
+push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc)
 {
     const char **argv = make_extended_arg_array(p, false, gc);
     char *opt = print_argv(argv, gc, 0);
@@ -914,8 +914,8 @@
 }
 
 static bool
-push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel, const char *format,
-                ...)
+push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                msglvl_t msglevel, const char *format, ...)
 {
     va_list arglist;
     char tmp[256] = { 0 };
src/openvpn/push.h +2 -2
index 8ffd0c2..6b3275e 100644
@@ -99,9 +99,9 @@
 
 void clone_push_list(struct options *o);
 
-void push_option(struct options *o, const char *opt, int msglevel);
+void push_option(struct options *o, const char *opt, msglvl_t msglevel);
 
-void push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc);
+void push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc);
 
 void push_reset(struct options *o);
 
src/openvpn/route.c +13 -13
index d3d2954..156a99e 100644
@@ -1228,28 +1228,28 @@
 }
 
 static void
-print_route_option(const struct route_option *ro, int level)
+print_route_option(const struct route_option *ro, msglvl_t msglevel)
 {
-    msg(level, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
+    msg(msglevel, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
         show_opt(ro->gateway), show_opt(ro->metric));
 }
 
 void
-print_route_options(const struct route_option_list *rol, int level)
+print_route_options(const struct route_option_list *rol, msglvl_t msglevel)
 {
     struct route_option *ro;
     if (rol->flags & RG_ENABLE)
     {
-        msg(level, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
+        msg(msglevel, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
     }
     for (ro = rol->routes; ro; ro = ro->next)
     {
-        print_route_option(ro, level);
+        print_route_option(ro, msglevel);
     }
 }
 
 void
-print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi,
                       const struct route_ipv6_gateway_info *rgi6)
 {
     struct gc_arena gc = gc_new();
@@ -1323,23 +1323,23 @@
 #endif /* ifndef ENABLE_SMALL */
 
 static void
-print_route(const struct route_ipv4 *r, int level)
+print_route(const struct route_ipv4 *r, msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     if (r->flags & RT_DEFINED)
     {
-        msg(level, "%s", route_string(r, &gc));
+        msg(msglevel, "%s", route_string(r, &gc));
     }
     gc_free(&gc);
 }
 
 void
-print_routes(const struct route_list *rl, int level)
+print_routes(const struct route_list *rl, msglvl_t msglevel)
 {
     struct route_ipv4 *r;
     for (r = rl->routes; r; r = r->next)
     {
-        print_route(r, level);
+        print_route(r, msglevel);
     }
 }
 
@@ -3067,18 +3067,18 @@
  * Show current routing table
  */
 void
-show_routes(int msglev)
+show_routes(msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
 
     const MIB_IPFORWARDTABLE *rt = get_windows_routing_table(&gc);
 
-    msg(msglev, "SYSTEM ROUTING TABLE");
+    msg(msglevel, "SYSTEM ROUTING TABLE");
     if (rt)
     {
         for (DWORD i = 0; i < rt->dwNumEntries; ++i)
         {
-            msg(msglev, "%s", format_route_entry(&rt->table[i], &gc));
+            msg(msglevel, "%s", format_route_entry(&rt->table[i], &gc));
         }
     }
     gc_free(&gc);
src/openvpn/route.h +4 -4
index 9b6a47e..c5006ae 100644
@@ -356,7 +356,7 @@
 void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi, const struct in6_addr *dest,
                               openvpn_net_ctx_t *ctx);
 
-void print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+void print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi,
                            const struct route_ipv6_gateway_info *rgi6);
 
 /*
@@ -371,15 +371,15 @@
 int test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi);
 
 #ifndef ENABLE_SMALL
-void print_route_options(const struct route_option_list *rol, int level);
+void print_route_options(const struct route_option_list *rol, msglvl_t msglevel);
 
 #endif
 
-void print_routes(const struct route_list *rl, int level);
+void print_routes(const struct route_list *rl, msglvl_t msglevel);
 
 #ifdef _WIN32
 
-void show_routes(int msglev);
+void show_routes(msglvl_t msglevel);
 
 bool test_routes(const struct route_list *rl, const struct tuntap *tt);
 
src/openvpn/run_command.c +1 -1
index 4a1ef22..a0c9484 100644
@@ -107,7 +107,7 @@
 
 #ifndef WIN32
 bool
-openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel)
+openvpn_waitpid_check(pid_t pid, const char *msg_prefix, msglvl_t msglevel)
 {
     if (pid == 0)
     {
src/openvpn/run_command.h +5 -5
index afd1b88..234055e 100644
@@ -71,13 +71,13 @@
  * This function is currently not implemented for Windows as the helper
  * macros used by this function are not available.
  *
- * @param pid               pid of the process to be checked
+ * @param pid            pid of the process to be checked
  * @param msg_prefix     prefixed of the message that be printed
- * @param msglevel          msglevel of the messages to be printed
- * @return                  true if the process is still running, false if
- *                          an error condition occurred
+ * @param msglevel       msglevel of the messages to be printed
+ * @return               true if the process is still running, false if
+ *                       an error condition occurred
  */
-bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel);
+bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, msglvl_t msglevel);
 
 #endif
 
src/openvpn/sig.c +1 -1
index ecea635..42ad823 100644
@@ -287,7 +287,7 @@
 }
 
 void
-print_signal(const struct signal_info *si, const char *title, int msglevel)
+print_signal(const struct signal_info *si, const char *title, msglvl_t msglevel)
 {
     if (si)
     {
src/openvpn/sig.h +1 -1
index 7e5dd9f..b5d81fc 100644
@@ -66,7 +66,7 @@
 
 void restore_signal_state(void);
 
-void print_signal(const struct signal_info *si, const char *title, int msglevel);
+void print_signal(const struct signal_info *si, const char *title, msglvl_t msglevel);
 
 void print_status(struct context *c, struct status_output *so);
 
src/openvpn/socket.c +4 -3
index 248c690..69445d9 100644
@@ -83,7 +83,7 @@
 static int
 get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname, void *network,
                  unsigned int *netbits, int resolve_retry_seconds, struct signal_info *sig_info,
-                 int msglevel)
+                 msglvl_t msglevel)
 {
     char *endp, *sep, *var_host = NULL;
     struct addrinfo *ai = NULL;
@@ -216,7 +216,8 @@
 }
 
 bool
-get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
+get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
+              msglvl_t msglevel)
 {
     if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostname, network, netbits, 0, NULL, msglevel)
         < 0)
@@ -1521,7 +1522,7 @@
 linksock_print_addr(struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
-    const int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
+    const msglvl_t msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
 
     /* print local address */
     if (sock->bind_local)
src/openvpn/socket_util.c +3 -3
index 9b7312d..fa566e7 100644
@@ -541,7 +541,7 @@
     struct addrinfo hints;
     int status;
     struct signal_info sigrec = { 0 };
-    int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
+    msglvl_t msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
     struct gc_arena gc = gc_new();
     const char *print_hostname;
     const char *print_servname;
@@ -604,7 +604,7 @@
         int resolve_retries =
             (flags & GETADDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) / fail_wait_interval);
         const char *fmt;
-        int level = 0;
+        msglvl_t level = 0;
 
         /* this is not a numeric IP, therefore force resolution using the
          * provided ai_family */
@@ -739,7 +739,7 @@
 done:
     if (sig_info && sig_info->signal_received)
     {
-        int level = 0;
+        msglvl_t level = 0;
         if (flags & GETADDR_FATAL_ON_SIGNAL)
         {
             level = M_FATAL;
src/openvpn/socket_util.h +1 -1
index 361edff..ada52a4 100644
@@ -142,7 +142,7 @@
  * Translate an IPv6 addr or hostname from string form to in6_addr
  */
 bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
-                   int msglevel);
+                   msglvl_t msglevel);
 
 int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname,
                         int resolve_retry_seconds, struct signal_info *sig_info, int ai_family,
src/openvpn/ssl_verify_backend.h +2 -2
index a0559c9..2bad3eb 100644
@@ -193,8 +193,8 @@
  * @param gc            Garbage collection arena for temp data
  *
  */
-void x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
-                    struct gc_arena *gc);
+void x509_track_add(const struct x509_track **ll_head, const char *name,
+                    msglvl_t msglevel, struct gc_arena *gc);
 
 /*
  * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_mbedtls.c +1 -1
index a2c702d..0915e3e 100644
@@ -359,7 +359,7 @@
 }
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, msglvl_t msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/ssl_verify_openssl.c +1 -1
index 122101c..12aae62 100644
@@ -414,7 +414,7 @@
  */
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, msglvl_t msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/status.c +2 -3
index fbd2168..a9f9498 100644
@@ -235,14 +235,13 @@
 
         if (so->msglevel >= 0 && !so->errors)
         {
-            msg(so->msglevel, "%s", buf);
+            msg((unsigned int)so->msglevel, "%s", buf);
         }
 
         if (so->fd >= 0 && !so->errors)
         {
-            int len;
             strcat(buf, "\n");
-            len = strlen(buf);
+            size_t len = strlen(buf);
             if (len > 0)
             {
                 if (write(so->fd, buf, len) != len)
src/openvpn/status.h +1 -0
index 0c7a869..25e1663 100644
@@ -53,6 +53,7 @@
 
     char *filename;
     int fd;
+    /* NB: -1 is used to indicate that output should only go to the file */
     int msglevel;
     const struct virtual_output *vout;
 
src/openvpn/tun.c +27 -27

146 lines not on this page · raw message

src/openvpn/tun.h +2 -2
index 06fc729..ce59276 100644
@@ -445,9 +445,9 @@
 DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count,
                           in_addr_t *netmask);
 
-void show_tap_win_adapters(int msglev, int warnlev);
+void show_tap_win_adapters(msglvl_t msglevel, unsigned int warnlevel);
 
-void show_adapters(int msglev);
+void show_adapters(msglvl_t msglevel);
 
 void tap_allow_nonadmin_access(const char *dev_node);
 
tests/unit_tests/openvpn/mock_msg.c +9 -9
index 603520b..69d2d1d 100644
@@ -38,8 +38,8 @@
 #include "error.h"
 #include "mock_msg.h"
 
-unsigned int x_debug_level = 0; /* Default to (almost) no debugging output */
-unsigned int print_x_debug_level = 0;
+msglvl_t x_debug_level = 0; /* Default to (almost) no debugging output */
+msglvl_t print_x_debug_level = 0;
 
 bool fatal_error_triggered = false;
 
@@ -47,31 +47,31 @@
 
 
 void
-mock_set_debug_level(int level)
+mock_set_debug_level(msglvl_t level)
 {
     x_debug_level = level;
 }
 
-int
+msglvl_t
 mock_get_debug_level(void)
 {
     return x_debug_level;
 }
 
 void
-mock_set_print_debug_level(int level)
+mock_set_print_debug_level(msglvl_t level)
 {
     print_x_debug_level = level;
 }
 
-int
+msglvl_t
 get_debug_level(void)
 {
     return x_debug_level;
 }
 
 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const msglvl_t flags, const char *format, va_list arglist)
 {
     if (flags & M_FATAL)
     {
@@ -89,7 +89,7 @@
 }
 
 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const msglvl_t flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -128,7 +128,7 @@
 }
 
 bool
-dont_mute(unsigned int flags)
+dont_mute(msglvl_t flags)
 {
     return true;
 }
tests/unit_tests/openvpn/mock_msg.h +3 -5
index f4ebc23..6dddf0b 100644
@@ -28,17 +28,15 @@
  * this function from your test driver to increase debug output when you
  * need debug output.
  */
-void mock_set_debug_level(int level);
+void mock_set_debug_level(msglvl_t level);
 
 #define MOCK_MSG_BUF 2048
 
 extern bool fatal_error_triggered;
 extern char mock_msg_buf[MOCK_MSG_BUF];
 
-void mock_set_debug_level(int level);
+msglvl_t mock_get_debug_level(void);
 
-int mock_get_debug_level(void);
-
-void mock_set_print_debug_level(int level);
+void mock_set_print_debug_level(msglvl_t level);
 
 #endif /* MOCK_MSG */
tests/unit_tests/openvpn/mock_ssl_dependencies.c +1 -1
index 7333c47..f2fa93a 100644
@@ -38,7 +38,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_argv.c +1 -1
index a65857b..a04fabc 100644
@@ -23,7 +23,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  msglvl_t msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_misc.c +2 -2
index 3433b73..5260a31 100644
@@ -348,8 +348,8 @@
     assert_false(valid_integer("-2147483653", false));
 
 
-    int msglevel = D_LOW;
-    int saved_log_level = mock_get_debug_level();
+    msglvl_t msglevel = D_LOW;
+    msglvl_t saved_log_level = mock_get_debug_level();
     mock_set_debug_level(D_LOW);
 
     /* check happy path */
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
index 9ba6cfc..d568865 100644
@@ -59,7 +59,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_pkt.c +1 -1
index 5122766..b6c612b 100644
@@ -45,7 +45,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_push_update_msg.c +2 -2
index 87329b1..8a5beeb 100644
@@ -111,7 +111,7 @@
 
 #ifndef ENABLE_MANAGEMENT
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     return true;
 }
@@ -120,7 +120,7 @@
 int i;
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     if (res && res[i] && strcmp(res[i], str))
     {
tests/unit_tests/openvpn/test_socket.c +1 -1
index 2da2529..7f740ac 100644
@@ -59,7 +59,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_tls_crypt.c +1 -1
index 532bfcd..44d51fe 100644
@@ -98,7 +98,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  msglvl_t msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_user_pass.c +1 -1
index 460b37f..32ec59f 100644
@@ -73,7 +73,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 15
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-MessageType: newpatchset

#10 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: Introduce msglvl_t to unify msglevel type handling

In reply to a message not in the archive

Attention is currently required from: cron2, plaisthos.

Hello cron2, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email

to look at the new patch set (#16).

Change subject: Introduce msglvl_t to unify msglevel type handling
......................................................................

Introduce msglvl_t to unify msglevel type handling

msglevel was definitely unsigned as the first
argument to msg(), but many parts of the code
had it as signed. So this produced a LOT of
warnings when enabling -Wsign-conversion.

Introduce a msglvl_t typedef and switch all
users to it. This includes any values that
are stored in the msglevel field, including
debug level and mute level.

There is one exception in struct status_output
where -1 is a valid value in the API. Only
positive values are translated into standard
message levels.

Change-Id Id492cb774c6d022d06bb3cf5fec2a4bdd410e619

---
M src/openvpn/argv.c
M src/openvpn/argv.h
M src/openvpn/buffer.c
M src/openvpn/clinat.c
M src/openvpn/clinat.h
M src/openvpn/comp.c
M src/openvpn/comp.h
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/dco.c
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dns.c
M src/openvpn/dns.h
M src/openvpn/env_set.c
M src/openvpn/env_set.h
M src/openvpn/error.c
M src/openvpn/error.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/manage.c
M src/openvpn/manage.h
M src/openvpn/mtu.c
M src/openvpn/mtu.h
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/packet_id.c
M src/openvpn/pkcs11.c
M src/openvpn/plugin.c
M src/openvpn/plugin.h
M src/openvpn/pool.c
M src/openvpn/pool.h
M src/openvpn/proto.c
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/sig.c
M src/openvpn/sig.h
M src/openvpn/socket.c
M src/openvpn/socket_util.c
M src/openvpn/socket_util.h
M src/openvpn/ssl_verify_backend.h
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/status.c
M src/openvpn/status.h
M src/openvpn/tun.c
M src/openvpn/tun.h
M tests/unit_tests/openvpn/mock_msg.c
M tests/unit_tests/openvpn/mock_msg.h
M tests/unit_tests/openvpn/mock_ssl_dependencies.c M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_push_update_msg.c M tests/unit_tests/openvpn/test_socket.c
M tests/unit_tests/openvpn/test_tls_crypt.c M tests/unit_tests/openvpn/test_user_pass.c

69 files changed, 283 insertions(+), 275 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/1110/16

src/openvpn/argv.c +9 -9
index 903fc0a..79b541a 100644
@@ -235,14 +235,14 @@
 /**
  *  Write the arguments stored in a struct argv via the msg() command.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write.
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write.
  */
 void
-argv_msg(const int msglev, const struct argv *a)
+argv_msg(const msglvl_t msglevel, const struct argv *a)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s", argv_str(a, &gc, 0));
+    msg(msglevel, "%s", argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
@@ -250,16 +250,16 @@
  *  Similar to argv_msg() but prefixes the messages being written with a
  *  given string.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write
- *  @param prefix  Valid pointer to the prefix string
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write
+ *  @param prefix    Valid pointer to the prefix string
  *
  */
 void
-argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix)
+argv_msg_prefix(const msglvl_t msglevel, const struct argv *a, const char *prefix)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s: %s", prefix, argv_str(a, &gc, 0));
+    msg(msglevel, "%s: %s", prefix, argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
src/openvpn/argv.h +2 -2
index 056fe31..969d7b1 100644
@@ -47,9 +47,9 @@
 
 struct argv argv_insert_head(const struct argv *a, const char *head);
 
-void argv_msg(const int msglev, const struct argv *a);
+void argv_msg(const msglvl_t msglevel, const struct argv *a);
 
-void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix);
+void argv_msg_prefix(const msglvl_t msglevel, const struct argv *a, const char *prefix);
 
 void argv_parse_cmd(struct argv *a, const char *s);
 
src/openvpn/buffer.c +1 -1
index 0f0d17e..c0b85b2 100644
@@ -1127,7 +1127,7 @@
 {
     if (buf && buf->len)
     {
-        int msglevel = D_ALIGN_DEBUG;
+        msglvl_t msglevel = D_ALIGN_DEBUG;
         const unsigned int u = (unsigned int)BPTR(buf);
 
         if (u & (PAYLOAD_ALIGN - 1))
src/openvpn/clinat.c +3 -3
index 48a2057..b49d4bb 100644
@@ -47,7 +47,7 @@
 }
 
 void
-print_client_nat_list(const struct client_nat_option_list *list, int msglevel)
+print_client_nat_list(const struct client_nat_option_list *list, msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     int i;
@@ -101,7 +101,7 @@
 void
 add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                               const char *network, const char *netmask, const char *foreign_network,
-                              int msglevel)
+                              msglvl_t msglevel)
 {
     struct client_nat_entry e;
     bool ok;
@@ -159,7 +159,7 @@
 #endif
 
 static void
-print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const int msglevel)
+print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
 
src/openvpn/clinat.h +2 -2
index abfa0b7..7d787e0 100644
@@ -54,11 +54,11 @@
 void copy_client_nat_option_list(struct client_nat_option_list *dest,
                                  const struct client_nat_option_list *src);
 
-void print_client_nat_list(const struct client_nat_option_list *list, int msglevel);
+void print_client_nat_list(const struct client_nat_option_list *list, msglvl_t msglevel);
 
 void add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                                    const char *network, const char *netmask,
-                                   const char *foreign_network, int msglevel);
+                                   const char *foreign_network, msglvl_t msglevel);
 
 void client_nat_transform(const struct client_nat_option_list *list, struct buffer *ipbuf,
                           const int direction);
src/openvpn/comp.c +1 -1
index 1a2e775..9d35141 100644
@@ -159,7 +159,7 @@
 #endif /* USE_COMP */
 
 bool
-check_compression_settings_valid(struct compress_options *info, int msglevel)
+check_compression_settings_valid(struct compress_options *info, msglvl_t msglevel)
 {
     /*
      * We also allow comp-stub-v2 here as it technically allows escaping of
src/openvpn/comp.h +3 -1
index 0354896..1717029 100644
@@ -84,12 +84,14 @@
            && info->alg != COMP_ALG_UNDEF;
 }
 
+#include "error.h"
+
 /**
  * Checks if the compression settings are valid. Takes into account the
  * flags of allow-compression and also the whether algorithms are compiled
  * in
  */
-bool check_compression_settings_valid(struct compress_options *info, int msglevel);
+bool check_compression_settings_valid(struct compress_options *info, msglvl_t msglevel);
 
 #ifdef USE_COMP
 #include "buffer.h"
src/openvpn/crypto.c +1 -1
index 1535c78..0e930d6 100644
@@ -1618,7 +1618,7 @@
 }
 
 int
-ascii2keydirection(int msglevel, const char *str)
+ascii2keydirection(msglvl_t msglevel, const char *str)
 {
     if (!str)
     {
src/openvpn/crypto.h +1 -1
index efd7f60..d69db59 100644
@@ -618,7 +618,7 @@
 
 void must_have_n_keys(const char *filename, const char *option, const struct key2 *key2, int n);
 
-int ascii2keydirection(int msglevel, const char *str);
+int ascii2keydirection(msglvl_t msglevel, const char *str);
 
 const char *keydirection2ascii(int kd, bool remote, bool humanreadable);
 
src/openvpn/dco.c +4 -4
index 823b4f9..2cf90af 100644
@@ -233,7 +233,7 @@
 }
 
 static bool
-dco_check_option_ce(const struct connection_entry *ce, int msglevel, int mode)
+dco_check_option_ce(const struct connection_entry *ce, msglvl_t msglevel, int mode)
 {
     if (ce->fragment)
     {
@@ -293,7 +293,7 @@
 }
 
 bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(msglvl_t msglevel, const struct options *o)
 {
     /* check if no dev name was specified at all. In the case,
      * later logic will most likely stop OpenVPN, so no need to
@@ -430,7 +430,7 @@
 }
 
 bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(msglvl_t msglevel, const struct options *o)
 {
     /* At this point the ciphers have already been normalised */
     if (o->enable_ncp_fallback
@@ -480,7 +480,7 @@
 }
 
 bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(msglvl_t msglevel, const struct options *o)
 {
     if (!o->use_peer_id)
     {
src/openvpn/dco.h +8 -8
index 59acb18..a362977 100644
@@ -55,7 +55,7 @@
  * @param msglevel      level to print messages to
  * @return              true if ovpn-dco is available, false otherwise
  */
-bool dco_available(int msglevel);
+bool dco_available(msglvl_t msglevel);
 
 
 /**
@@ -75,7 +75,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_option(int msglevel, const struct options *o);
+bool dco_check_option(msglvl_t msglevel, const struct options *o);
 
 /**
  * Check whether the options struct has any further option that is not supported
@@ -87,7 +87,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_startup_option(int msglevel, const struct options *o);
+bool dco_check_startup_option(msglvl_t msglevel, const struct options *o);
 
 /**
  * Check whether any of the options pushed by the server is not supported by
@@ -98,7 +98,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_pull_options(int msglevel, const struct options *o);
+bool dco_check_pull_options(msglvl_t msglevel, const struct options *o);
 
 /**
  * Initialize the DCO context
@@ -261,7 +261,7 @@
 typedef void *dco_context_t;
 
 static inline bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     return false;
 }
@@ -273,19 +273,19 @@
 }
 
 static inline bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
src/openvpn/dco_freebsd.c +1 -1
index 56a774d..b9f6bc7 100644
@@ -663,7 +663,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     struct if_clonereq ifcr;
     char *buf = NULL;
src/openvpn/dco_linux.c +2 -2
index 3b08f33..395a38f 100644
@@ -79,7 +79,7 @@
  * @return ID on success, negative error code on error
  */
 static int
-resolve_ovpn_netlink_id(int msglevel)
+resolve_ovpn_netlink_id(msglvl_t msglevel)
 {
     int ret;
     struct nl_sock *nl_sock = nl_socket_alloc();
@@ -1204,7 +1204,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0)
     {
src/openvpn/dco_win.c +1 -1
index 1dc5cf8..9e52859 100644
@@ -609,7 +609,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     /* try to open device by symbolic name */
     HANDLE h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
src/openvpn/dns.c +1 -1
index 5421004..efb888a 100644
@@ -200,7 +200,7 @@
 }
 
 bool
-dns_options_verify(int msglevel, const struct dns_options *o)
+dns_options_verify(msglvl_t msglevel, const struct dns_options *o)
 {
     const struct dns_server *server = o->servers ? o->servers : o->servers_prepull;
     while (server)
src/openvpn/dns.h +1 -1
index 6d97b40..6cd98f2 100644
@@ -166,7 +166,7 @@
  * @param   o           Pointer to the DNS options to validate
  * @return              True if no error was found
  */
-bool dns_options_verify(int msglevel, const struct dns_options *o);
+bool dns_options_verify(msglvl_t msglevel, const struct dns_options *o);
 
 /**
  * Makes a deep copy of the passed DNS options.
src/openvpn/env_set.c +1 -1
index 6c7df8e..2ae71ab 100644
@@ -209,7 +209,7 @@
 }
 
 void
-env_set_print(int msglevel, const struct env_set *es)
+env_set_print(msglvl_t msglevel, const struct env_set *es)
 {
     if (check_debug_level(msglevel))
     {
src/openvpn/env_set.h +1 -1
index 3973a4e..ddcfa14 100644
@@ -85,7 +85,7 @@
 
 const char *env_set_get(const struct env_set *es, const char *name);
 
-void env_set_print(int msglevel, const struct env_set *es);
+void env_set_print(msglvl_t msglevel, const struct env_set *es);
 
 /**
  * Write a struct env_set to a file. Each item on one line.
src/openvpn/error.c +15 -17
index 1b98235..58c2fd1 100644
@@ -48,12 +48,12 @@
 #endif
 
 /* Globals */
-unsigned int x_debug_level; /* GLOBAL */
+msglvl_t x_debug_level; /* GLOBAL */
 
 /* Mute state */
-static int mute_cutoff;   /* GLOBAL */
-static int mute_count;    /* GLOBAL */
-static int mute_category; /* GLOBAL */
+static int mute_cutoff;        /* GLOBAL */
+static int mute_count;         /* GLOBAL */
+static msglvl_t mute_category; /* GLOBAL */
 
 /*
  * Output mode priorities are as follows:
@@ -103,16 +103,14 @@
 bool
 set_debug_level(const int level, const unsigned int flags)
 {
-    const int ceiling = 15;
-
-    if (level >= 0 && level <= ceiling)
+    if (level >= 0 && level <= M_DEBUG_LEVEL)
     {
-        x_debug_level = level;
+        x_debug_level = (msglvl_t)level;
         return true;
     }
     else if (flags & SDL_CONSTRAIN)
     {
-        x_debug_level = constrain_int(level, 0, ceiling);
+        x_debug_level = (msglvl_t)constrain_int(level, 0, M_DEBUG_LEVEL);
         return true;
     }
     return false;
@@ -132,7 +130,7 @@
     }
 }
 
-int
+msglvl_t
 get_debug_level(void)
 {
     return x_debug_level;
@@ -190,7 +188,7 @@
  * Return a file to print messages to before syslog is opened.
  */
 FILE *
-msg_fp(const unsigned int flags)
+msg_fp(const msglvl_t flags)
 {
     FILE *fp = msgfp;
     if (!fp)
@@ -214,7 +212,7 @@
 int x_msg_line_num; /* GLOBAL */
 
 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const msglvl_t flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -235,7 +233,7 @@
 }
 
 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const msglvl_t flags, const char *format, va_list arglist)
 {
     struct gc_arena gc;
 #if SYSLOG_CAPABILITY
@@ -385,13 +383,13 @@
  * Apply muting filter.
  */
 bool
-dont_mute(unsigned int flags)
+dont_mute(msglvl_t flags)
 {
     bool ret = true;
     if (mute_cutoff > 0 && !(flags & M_NOMUTE))
     {
-        const int mute_level = DECODE_MUTE_LEVEL(flags);
-        if (mute_level > 0 && mute_level == mute_category)
+        const msglvl_t mute_level = DECODE_MUTE_LEVEL(flags);
+        if (mute_level == mute_category)
         {
             if (mute_count == mute_cutoff)
             {
@@ -750,7 +748,7 @@
  * Translate msg flags into a string
  */
 const char *
-msg_flags_string(const unsigned int flags, struct gc_arena *gc)
+msg_flags_string(const msglvl_t flags, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(16, gc);
     if (flags == M_INFO)
src/openvpn/error.h +27 -25

124 lines not on this page · raw message

src/openvpn/forward.c +3 -2
index e82b544..f342958 100644
@@ -373,7 +373,8 @@
 #endif
 
 bool
-send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel)
+send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                   msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     bool stat;
@@ -400,7 +401,7 @@
 }
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     if (c->c2.tls_multi)
     {
src/openvpn/forward.h +3 -2
index 79d0f8b..a575faf 100644
@@ -285,7 +285,7 @@
  * @param str        - The message to be sent
  * @param msglevel   - Message level to use for logging
  */
-bool send_control_channel_string(struct context *c, const char *str, int msglevel);
+bool send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel);
 
 /*
  * Send a string to remote over the TLS control channel.
@@ -303,7 +303,8 @@
  * @param msglevel   - Message level to use for logging
  */
 
-bool send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel);
+bool send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                        msglvl_t msglevel);
 
 
 /**
src/openvpn/init.c +1 -1
index 24aebc0..f8a0fee 100644
@@ -4282,7 +4282,7 @@
 }
 
 void
-management_show_net_callback(void *arg, const int msglevel)
+management_show_net_callback(void *arg, const msglvl_t msglevel)
 {
 #ifdef _WIN32
     show_routes(msglevel);
src/openvpn/init.h +1 -1
index a807874..e89615b 100644
@@ -136,7 +136,7 @@
 
 void close_management(void);
 
-void management_show_net_callback(void *arg, const int msglevel);
+void management_show_net_callback(void *arg, const msglvl_t msglevel);
 
 #endif
 
src/openvpn/manage.c +1 -1
index 4f37bd2..5a41a0f 100644
@@ -1484,7 +1484,7 @@
         }
         else
         {
-            msg(M_CLIENT, "SUCCESS: verb=%d", get_debug_level());
+            msg(M_CLIENT, "SUCCESS: verb=%u", get_debug_level());
         }
     }
     else if (streq(p[0], "mute"))
src/openvpn/manage.h +1 -1
index 7c189ba..bff96d3 100644
@@ -176,7 +176,7 @@
     unsigned int flags;
 
     void (*status)(void *arg, const int version, struct status_output *so);
-    void (*show_net)(void *arg, const int msglevel);
+    void (*show_net)(void *arg, const msglvl_t msglevel);
     int (*kill_by_cn)(void *arg, const char *common_name);
     int (*kill_by_addr)(void *arg, const in_addr_t addr, const int port, const int proto);
     void (*delete_event)(void *arg, event_t event);
src/openvpn/mtu.c +2 -2
index 1e021e3..66f81a6 100644
@@ -187,7 +187,7 @@
 }
 
 void
-frame_print(const struct frame *frame, int level, const char *prefix)
+frame_print(const struct frame *frame, msglvl_t msglevel, const char *prefix)
 {
     struct gc_arena gc = gc_new();
     struct buffer out = alloc_buf_gc(256, &gc);
@@ -208,7 +208,7 @@
     buf_printf(&out, " ET:%d", frame->extra_tun);
     buf_printf(&out, " ]");
 
-    msg(level, "%s", out.data);
+    msg(msglevel, "%s", out.data);
     gc_free(&gc);
 }
 
src/openvpn/mtu.h +1 -1
index c092461..3bbff6f 100644
@@ -181,7 +181,7 @@
  * Function prototypes.
  */
 
-void frame_print(const struct frame *frame, int level, const char *prefix);
+void frame_print(const struct frame *frame, msglvl_t msglevel, const char *prefix);
 
 void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af);
 
src/openvpn/multi.c +1 -1
index 579eeea..3877f8d 100644
@@ -3321,7 +3321,7 @@
     }
     else
     {
-        int msglevel = D_DCO;
+        msglvl_t msglevel = D_DCO;
         if (dco->dco_message_type == OVPN_CMD_DEL_PEER
             && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
         {
src/openvpn/options.c +52 -48

330 lines not on this page · raw message

src/openvpn/options.h +6 -6
index bb2c052..a737711 100644
@@ -822,7 +822,7 @@
     struct pull_filter *tail;
 };
 
-void parse_argv(struct options *options, const int argc, char *argv[], const int msglevel,
+void parse_argv(struct options *options, const int argc, char *argv[], const msglvl_t msglevel,
                 const unsigned int permission_mask, unsigned int *option_types_found,
                 struct env_set *es);
 
@@ -888,7 +888,7 @@
 
 void options_detach(struct options *o);
 
-void options_server_import(struct options *o, const char *filename, int msglevel,
+void options_server_import(struct options *o, const char *filename, msglvl_t msglevel,
                            unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
@@ -897,13 +897,13 @@
 void rol_check_alloc(struct options *options);
 
 int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num,
-               int msglevel, struct gc_arena *gc);
+               msglvl_t msglevel, struct gc_arena *gc);
 
 /*
  * parse/print topology coding
  */
 
-int parse_topology(const char *str, const int msglevel);
+int parse_topology(const char *str, const msglvl_t msglevel);
 
 const char *print_topology(const int topology);
 
@@ -917,11 +917,11 @@
 
 int auth_retry_get(void);
 
-bool auth_retry_set(const int msglevel, const char *option);
+bool auth_retry_set(const msglvl_t msglevel, const char *option);
 
 const char *auth_retry_print(void);
 
-void options_string_import(struct options *options, const char *config, const int msglevel,
+void options_string_import(struct options *options, const char *config, const msglvl_t msglevel,
                            const unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
src/openvpn/options_util.c +4 -4
index a351967..125d47c 100644
@@ -117,7 +117,7 @@
 }
 
 int
-positive_atoi(const char *str, int msglevel)
+positive_atoi(const char *str, msglvl_t msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -132,7 +132,7 @@
 }
 
 bool
-positive_atoll(const char *str, int64_t *value, const char *name, int msglevel)
+positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel)
 {
     char *endptr;
     long long ll = strtoll(str, &endptr, 10);
@@ -148,7 +148,7 @@
 }
 
 int
-atoi_warn(const char *str, int msglevel)
+atoi_warn(const char *str, msglvl_t msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -168,7 +168,7 @@
 #endif
 
 bool
-atoi_constrained(const char *str, int *value, const char *name, int min, int max, int msglevel)
+atoi_constrained(const char *str, int *value, const char *name, int min, int max, msglvl_t msglevel)
 {
     ASSERT(min < max);
 
src/openvpn/options_util.h +4 -4
index 45417d9..1492eef 100644
@@ -37,7 +37,7 @@
  * Converts a str to a positive number if the string represents a postive
  * integer number. Otherwise print a warning with msglevel and return 0
  */
-int positive_atoi(const char *str, int msglevel);
+int positive_atoi(const char *str, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -48,13 +48,13 @@
  *
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
-bool positive_atoll(const char *str, int64_t *value, const char *name, int msglevel);
+bool positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
  * integer number. Otherwise print a warning with \p msglevel and return 0
  */
-int atoi_warn(const char *str, int msglevel);
+int atoi_warn(const char *str, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -66,7 +66,7 @@
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
 bool atoi_constrained(const char *str, int *value, const char *name, int min, int max,
-                      int msglevel);
+                      msglvl_t msglevel);
 
 /**
  * Filter an option line by all pull filters.
src/openvpn/packet_id.c +5 -4
index 0b33c9c..880eee1 100644
@@ -53,15 +53,15 @@
 #define SEQ_EXPIRED ((time_t)1)
 
 #ifdef ENABLE_DEBUG
-static void packet_id_debug_print(int msglevel, const struct packet_id_rec *p,
+static void packet_id_debug_print(msglvl_t msglevel, const struct packet_id_rec *p,
                                   const struct packet_id_net *pin, const char *message,
                                   packet_id_print_type value);
 
 #endif /* ENABLE_DEBUG */
 
 static inline void
-packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
-                const char *message, uint64_t value)
+packet_id_debug(msglvl_t msglevel, const struct packet_id_rec *p,
+                const struct packet_id_net *pin, const char *message, uint64_t value)
 {
 #ifdef ENABLE_DEBUG
     if (unlikely(check_debug_level(msglevel)))
@@ -578,7 +578,8 @@
 #ifdef ENABLE_DEBUG
 
 static void
-packet_id_debug_print(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
+packet_id_debug_print(msglvl_t msglevel, const struct packet_id_rec *p,
+                      const struct packet_id_net *pin,
                       const char *message, packet_id_print_type value)
 {
     struct gc_arena gc = gc_new();
src/openvpn/pkcs11.c +3 -3
index d9c16d9..16149ca 100644
@@ -77,10 +77,10 @@
 #endif
 };
 
-static unsigned
+static msglvl_t
 _pkcs11_msg_pkcs112openvpn(const unsigned flags)
 {
-    unsigned openvpn_flags;
+    msglvl_t openvpn_flags;
 
     switch (flags)
     {
@@ -117,7 +117,7 @@
 }
 
 static unsigned
-_pkcs11_msg_openvpn2pkcs11(const unsigned flags)
+_pkcs11_msg_openvpn2pkcs11(const msglvl_t flags)
 {
     unsigned pkcs11_flags;
 
src/openvpn/plugin.c +4 -4
index ea76a08..a105058 100644
@@ -50,7 +50,7 @@
 static struct plugin_common *static_plugin_common = NULL; /* GLOBAL */
 
 static void
-plugin_show_string_array(int msglevel, const char *name, const char *array[])
+plugin_show_string_array(msglvl_t msglevel, const char *name, const char *array[])
 {
     int i;
     for (i = 0; array[i]; ++i)
@@ -63,7 +63,7 @@
 }
 
 static void
-plugin_show_args_env(int msglevel, const char *argv[], const char *envp[])
+plugin_show_args_env(msglvl_t msglevel, const char *argv[], const char *envp[])
 {
     if (check_debug_level(msglevel))
     {
@@ -184,7 +184,7 @@
 
 #ifndef ENABLE_SMALL
 void
-plugin_option_list_print(const struct plugin_option_list *list, int msglevel)
+plugin_option_list_print(const struct plugin_option_list *list, msglvl_t msglevel)
 {
     int i;
     struct gc_arena gc = gc_new();
@@ -995,7 +995,7 @@
 
 #ifdef ENABLE_DEBUG
 void
-plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr)
+plugin_return_print(const msglvl_t msglevel, const char *prefix, const struct plugin_return *pr)
 {
     int i;
     msg(msglevel, "PLUGIN_RETURN_PRINT %s", prefix);
src/openvpn/plugin.h +2 -2
index 63999b6..81d3739 100644
@@ -111,7 +111,7 @@
 bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc);
 
 #ifndef ENABLE_SMALL
-void plugin_option_list_print(const struct plugin_option_list *list, int msglevel);
+void plugin_option_list_print(const struct plugin_option_list *list, msglvl_t msglevel);
 
 #endif
 
@@ -136,7 +136,7 @@
 void plugin_return_free(struct plugin_return *pr);
 
 #ifdef ENABLE_DEBUG
-void plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr);
+void plugin_return_print(const msglvl_t msglevel, const char *prefix, const struct plugin_return *pr);
 
 #endif
 
src/openvpn/pool.c +1 -1
index fde6cea..28ddd2c 100644
@@ -114,7 +114,7 @@
  * Verify start/end range
  */
 bool
-ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end)
+ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end)
 {
     struct gc_arena gc = gc_new();
     bool ret = true;
src/openvpn/pool.h +1 -1
index 6cecef0..36e9fca 100644
@@ -78,7 +78,7 @@
 
 void ifconfig_pool_free(struct ifconfig_pool *pool);
 
-bool ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end);
+bool ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end);
 
 ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local,
                                            in_addr_t *remote, struct in6_addr *remote_ipv6,
src/openvpn/proto.c +1 -1
index 34b3378..ab77887 100644
@@ -183,7 +183,7 @@
             int hlen;
             int totlen;
             const char *msgstr = "PACKET SIZE INFO";
-            unsigned int msglevel = D_PACKET_TRUNC_DEBUG;
+            msglvl_t msglevel = D_PACKET_TRUNC_DEBUG;
 
             if (BLEN(&buf) < (int)sizeof(struct openvpn_iphdr))
             {
src/openvpn/push.c +7 -7
index 671b015..e7fc50c 100644
@@ -373,8 +373,8 @@
  *
  * @return true on success, false on failure.
  */
-static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel,
-                            const char *fmt, ...)
+static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                            msglvl_t msglevel, const char *fmt, ...)
 #ifdef __GNUC__
 #if __USE_MINGW_ANSI_STDIO
     __attribute__((format(gnu_printf, 4, 5)))
@@ -857,7 +857,7 @@
 
 static void
 push_option_ex(struct gc_arena *gc, struct push_list *push_list, const char *opt, bool enable,
-               int msglevel)
+               msglvl_t msglevel)
 {
     if (!string_class(opt, CC_ANY, CC_COMMA))
     {
@@ -885,7 +885,7 @@
 }
 
 void
-push_option(struct options *o, const char *opt, int msglevel)
+push_option(struct options *o, const char *opt, msglvl_t msglevel)
 {
     push_option_ex(&o->gc, &o->push_list, opt, true, msglevel);
 }
@@ -906,7 +906,7 @@
 }
 
 void
-push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc)
+push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc)
 {
     const char **argv = make_extended_arg_array(p, false, gc);
     char *opt = print_argv(argv, gc, 0);
@@ -914,8 +914,8 @@
 }
 
 static bool
-push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel, const char *format,
-                ...)
+push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                msglvl_t msglevel, const char *format, ...)
 {
     va_list arglist;
     char tmp[256] = { 0 };
src/openvpn/push.h +2 -2
index 8ffd0c2..6b3275e 100644
@@ -99,9 +99,9 @@
 
 void clone_push_list(struct options *o);
 
-void push_option(struct options *o, const char *opt, int msglevel);
+void push_option(struct options *o, const char *opt, msglvl_t msglevel);
 
-void push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc);
+void push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc);
 
 void push_reset(struct options *o);
 
src/openvpn/route.c +13 -13
index d3d2954..156a99e 100644
@@ -1228,28 +1228,28 @@
 }
 
 static void
-print_route_option(const struct route_option *ro, int level)
+print_route_option(const struct route_option *ro, msglvl_t msglevel)
 {
-    msg(level, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
+    msg(msglevel, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
         show_opt(ro->gateway), show_opt(ro->metric));
 }
 
 void
-print_route_options(const struct route_option_list *rol, int level)
+print_route_options(const struct route_option_list *rol, msglvl_t msglevel)
 {
     struct route_option *ro;
     if (rol->flags & RG_ENABLE)
     {
-        msg(level, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
+        msg(msglevel, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
     }
     for (ro = rol->routes; ro; ro = ro->next)
     {
-        print_route_option(ro, level);
+        print_route_option(ro, msglevel);
     }
 }
 
 void
-print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi,
                       const struct route_ipv6_gateway_info *rgi6)
 {
     struct gc_arena gc = gc_new();
@@ -1323,23 +1323,23 @@
 #endif /* ifndef ENABLE_SMALL */
 
 static void
-print_route(const struct route_ipv4 *r, int level)
+print_route(const struct route_ipv4 *r, msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     if (r->flags & RT_DEFINED)
     {
-        msg(level, "%s", route_string(r, &gc));
+        msg(msglevel, "%s", route_string(r, &gc));
     }
     gc_free(&gc);
 }
 
 void
-print_routes(const struct route_list *rl, int level)
+print_routes(const struct route_list *rl, msglvl_t msglevel)
 {
     struct route_ipv4 *r;
     for (r = rl->routes; r; r = r->next)
     {
-        print_route(r, level);
+        print_route(r, msglevel);
     }
 }
 
@@ -3067,18 +3067,18 @@
  * Show current routing table
  */
 void
-show_routes(int msglev)
+show_routes(msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
 
     const MIB_IPFORWARDTABLE *rt = get_windows_routing_table(&gc);
 
-    msg(msglev, "SYSTEM ROUTING TABLE");
+    msg(msglevel, "SYSTEM ROUTING TABLE");
     if (rt)
     {
         for (DWORD i = 0; i < rt->dwNumEntries; ++i)
         {
-            msg(msglev, "%s", format_route_entry(&rt->table[i], &gc));
+            msg(msglevel, "%s", format_route_entry(&rt->table[i], &gc));
         }
     }
     gc_free(&gc);
src/openvpn/route.h +4 -4
index 9b6a47e..c5006ae 100644
@@ -356,7 +356,7 @@
 void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi, const struct in6_addr *dest,
                               openvpn_net_ctx_t *ctx);
 
-void print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+void print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi,
                            const struct route_ipv6_gateway_info *rgi6);
 
 /*
@@ -371,15 +371,15 @@
 int test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi);
 
 #ifndef ENABLE_SMALL
-void print_route_options(const struct route_option_list *rol, int level);
+void print_route_options(const struct route_option_list *rol, msglvl_t msglevel);
 
 #endif
 
-void print_routes(const struct route_list *rl, int level);
+void print_routes(const struct route_list *rl, msglvl_t msglevel);
 
 #ifdef _WIN32
 
-void show_routes(int msglev);
+void show_routes(msglvl_t msglevel);
 
 bool test_routes(const struct route_list *rl, const struct tuntap *tt);
 
src/openvpn/run_command.c +1 -1
index 4a1ef22..a0c9484 100644
@@ -107,7 +107,7 @@
 
 #ifndef WIN32
 bool
-openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel)
+openvpn_waitpid_check(pid_t pid, const char *msg_prefix, msglvl_t msglevel)
 {
     if (pid == 0)
     {
src/openvpn/run_command.h +5 -5
index afd1b88..234055e 100644
@@ -71,13 +71,13 @@
  * This function is currently not implemented for Windows as the helper
  * macros used by this function are not available.
  *
- * @param pid               pid of the process to be checked
+ * @param pid            pid of the process to be checked
  * @param msg_prefix     prefixed of the message that be printed
- * @param msglevel          msglevel of the messages to be printed
- * @return                  true if the process is still running, false if
- *                          an error condition occurred
+ * @param msglevel       msglevel of the messages to be printed
+ * @return               true if the process is still running, false if
+ *                       an error condition occurred
  */
-bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel);
+bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, msglvl_t msglevel);
 
 #endif
 
src/openvpn/sig.c +1 -1
index ecea635..42ad823 100644
@@ -287,7 +287,7 @@
 }
 
 void
-print_signal(const struct signal_info *si, const char *title, int msglevel)
+print_signal(const struct signal_info *si, const char *title, msglvl_t msglevel)
 {
     if (si)
     {
src/openvpn/sig.h +1 -1
index 7e5dd9f..b5d81fc 100644
@@ -66,7 +66,7 @@
 
 void restore_signal_state(void);
 
-void print_signal(const struct signal_info *si, const char *title, int msglevel);
+void print_signal(const struct signal_info *si, const char *title, msglvl_t msglevel);
 
 void print_status(struct context *c, struct status_output *so);
 
src/openvpn/socket.c +4 -3
index 248c690..69445d9 100644
@@ -83,7 +83,7 @@
 static int
 get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname, void *network,
                  unsigned int *netbits, int resolve_retry_seconds, struct signal_info *sig_info,
-                 int msglevel)
+                 msglvl_t msglevel)
 {
     char *endp, *sep, *var_host = NULL;
     struct addrinfo *ai = NULL;
@@ -216,7 +216,8 @@
 }
 
 bool
-get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
+get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
+              msglvl_t msglevel)
 {
     if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostname, network, netbits, 0, NULL, msglevel)
         < 0)
@@ -1521,7 +1522,7 @@
 linksock_print_addr(struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
-    const int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
+    const msglvl_t msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
 
     /* print local address */
     if (sock->bind_local)
src/openvpn/socket_util.c +3 -3
index 9b7312d..fa566e7 100644
@@ -541,7 +541,7 @@
     struct addrinfo hints;
     int status;
     struct signal_info sigrec = { 0 };
-    int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
+    msglvl_t msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
     struct gc_arena gc = gc_new();
     const char *print_hostname;
     const char *print_servname;
@@ -604,7 +604,7 @@
         int resolve_retries =
             (flags & GETADDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) / fail_wait_interval);
         const char *fmt;
-        int level = 0;
+        msglvl_t level = 0;
 
         /* this is not a numeric IP, therefore force resolution using the
          * provided ai_family */
@@ -739,7 +739,7 @@
 done:
     if (sig_info && sig_info->signal_received)
     {
-        int level = 0;
+        msglvl_t level = 0;
         if (flags & GETADDR_FATAL_ON_SIGNAL)
         {
             level = M_FATAL;
src/openvpn/socket_util.h +1 -1
index 361edff..ada52a4 100644
@@ -142,7 +142,7 @@
  * Translate an IPv6 addr or hostname from string form to in6_addr
  */
 bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
-                   int msglevel);
+                   msglvl_t msglevel);
 
 int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname,
                         int resolve_retry_seconds, struct signal_info *sig_info, int ai_family,
src/openvpn/ssl_verify_backend.h +2 -2
index a0559c9..2bad3eb 100644
@@ -193,8 +193,8 @@
  * @param gc            Garbage collection arena for temp data
  *
  */
-void x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
-                    struct gc_arena *gc);
+void x509_track_add(const struct x509_track **ll_head, const char *name,
+                    msglvl_t msglevel, struct gc_arena *gc);
 
 /*
  * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_mbedtls.c +1 -1
index a2c702d..0915e3e 100644
@@ -359,7 +359,7 @@
 }
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, msglvl_t msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/ssl_verify_openssl.c +1 -1
index 122101c..12aae62 100644
@@ -414,7 +414,7 @@
  */
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, msglvl_t msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/status.c +2 -3
index fbd2168..1e1e3fb 100644
@@ -235,14 +235,13 @@
 
         if (so->msglevel >= 0 && !so->errors)
         {
-            msg(so->msglevel, "%s", buf);
+            msg((msglvl_t)so->msglevel, "%s", buf);
         }
 
         if (so->fd >= 0 && !so->errors)
         {
-            int len;
             strcat(buf, "\n");
-            len = strlen(buf);
+            size_t len = strlen(buf);
             if (len > 0)
             {
                 if (write(so->fd, buf, len) != len)
src/openvpn/status.h +1 -0
index 0c7a869..25e1663 100644
@@ -53,6 +53,7 @@
 
     char *filename;
     int fd;
+    /* NB: -1 is used to indicate that output should only go to the file */
     int msglevel;
     const struct virtual_output *vout;
 
src/openvpn/tun.c +27 -27

146 lines not on this page · raw message

src/openvpn/tun.h +2 -2
index 06fc729..6562c22 100644
@@ -445,9 +445,9 @@
 DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count,
                           in_addr_t *netmask);
 
-void show_tap_win_adapters(int msglev, int warnlev);
+void show_tap_win_adapters(msglvl_t msglevel, msglvl_t warnlevel);
 
-void show_adapters(int msglev);
+void show_adapters(msglvl_t msglevel);
 
 void tap_allow_nonadmin_access(const char *dev_node);
 
tests/unit_tests/openvpn/mock_msg.c +9 -9
index 603520b..69d2d1d 100644
@@ -38,8 +38,8 @@
 #include "error.h"
 #include "mock_msg.h"
 
-unsigned int x_debug_level = 0; /* Default to (almost) no debugging output */
-unsigned int print_x_debug_level = 0;
+msglvl_t x_debug_level = 0; /* Default to (almost) no debugging output */
+msglvl_t print_x_debug_level = 0;
 
 bool fatal_error_triggered = false;
 
@@ -47,31 +47,31 @@
 
 
 void
-mock_set_debug_level(int level)
+mock_set_debug_level(msglvl_t level)
 {
     x_debug_level = level;
 }
 
-int
+msglvl_t
 mock_get_debug_level(void)
 {
     return x_debug_level;
 }
 
 void
-mock_set_print_debug_level(int level)
+mock_set_print_debug_level(msglvl_t level)
 {
     print_x_debug_level = level;
 }
 
-int
+msglvl_t
 get_debug_level(void)
 {
     return x_debug_level;
 }
 
 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const msglvl_t flags, const char *format, va_list arglist)
 {
     if (flags & M_FATAL)
     {
@@ -89,7 +89,7 @@
 }
 
 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const msglvl_t flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -128,7 +128,7 @@
 }
 
 bool
-dont_mute(unsigned int flags)
+dont_mute(msglvl_t flags)
 {
     return true;
 }
tests/unit_tests/openvpn/mock_msg.h +3 -5
index f4ebc23..6dddf0b 100644
@@ -28,17 +28,15 @@
  * this function from your test driver to increase debug output when you
  * need debug output.
  */
-void mock_set_debug_level(int level);
+void mock_set_debug_level(msglvl_t level);
 
 #define MOCK_MSG_BUF 2048
 
 extern bool fatal_error_triggered;
 extern char mock_msg_buf[MOCK_MSG_BUF];
 
-void mock_set_debug_level(int level);
+msglvl_t mock_get_debug_level(void);
 
-int mock_get_debug_level(void);
-
-void mock_set_print_debug_level(int level);
+void mock_set_print_debug_level(msglvl_t level);
 
 #endif /* MOCK_MSG */
tests/unit_tests/openvpn/mock_ssl_dependencies.c +1 -1
index 7333c47..f2fa93a 100644
@@ -38,7 +38,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_argv.c +1 -1
index a65857b..a04fabc 100644
@@ -23,7 +23,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  msglvl_t msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_misc.c +2 -2
index 3433b73..5260a31 100644
@@ -348,8 +348,8 @@
     assert_false(valid_integer("-2147483653", false));
 
 
-    int msglevel = D_LOW;
-    int saved_log_level = mock_get_debug_level();
+    msglvl_t msglevel = D_LOW;
+    msglvl_t saved_log_level = mock_get_debug_level();
     mock_set_debug_level(D_LOW);
 
     /* check happy path */
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
index 9ba6cfc..d568865 100644
@@ -59,7 +59,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_pkt.c +1 -1
index 5122766..b6c612b 100644
@@ -45,7 +45,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_push_update_msg.c +2 -2
index 87329b1..8a5beeb 100644
@@ -111,7 +111,7 @@
 
 #ifndef ENABLE_MANAGEMENT
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     return true;
 }
@@ -120,7 +120,7 @@
 int i;
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     if (res && res[i] && strcmp(res[i], str))
     {
tests/unit_tests/openvpn/test_socket.c +1 -1
index 2da2529..7f740ac 100644
@@ -59,7 +59,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_tls_crypt.c +1 -1
index 532bfcd..44d51fe 100644
@@ -98,7 +98,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  msglvl_t msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_user_pass.c +1 -1
index 460b37f..32ec59f 100644
@@ -73,7 +73,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 16
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-MessageType: newpatchset

#11 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: Introduce msglvl_t to unify msglevel type handling

In reply to a message not in the archive

Attention is currently required from: cron2, ordex, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email )

Change subject: Introduce msglvl_t to unify msglevel type handling
......................................................................

Patch Set 16:

(1 comment)

Patchset:

PS10:

Quoted 1 line

I just checked both patches and honestly it immediately looked weird to me that "flags" are stored i […]

Acknowledged

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 16
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 17 Sep 2025 15:56:29 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment

#12 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: Introduce msglvl_t to unify msglevel type handling

In reply to a message not in the archive

Attention is currently required from: flichtenheld, ordex, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email )

Change subject: Introduce msglvl_t to unify msglevel type handling
......................................................................

Patch Set 16: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 16
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 17 Sep 2025 17:03:38 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#13 lore raw

PATCH v16 1/1 Introduce msglvl_t to unify msglevel type handling

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

msglevel was definitely unsigned as the first argument to msg(), but many parts of the code had it as signed. So this produced a LOT of warnings when enabling -Wsign-conversion.

Introduce a msglvl_t typedef and switch all users to it. This includes any values that are stored in the msglevel field, including debug level and mute level.

There is one exception in struct status_output where -1 is a valid value in the API. Only positive values are translated into standard message levels.

Change-Id Id492cb774c6d022d06bb3cf5fec2a4bdd410e619

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1110
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1110
This mail reflects revision 16 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

src/openvpn/argv.c +9 -9
index 903fc0a..79b541a 100644
@@ -235,14 +235,14 @@
 /**
  *  Write the arguments stored in a struct argv via the msg() command.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write.
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write.
  */
 void
-argv_msg(const int msglev, const struct argv *a)
+argv_msg(const msglvl_t msglevel, const struct argv *a)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s", argv_str(a, &gc, 0));
+    msg(msglevel, "%s", argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
@@ -250,16 +250,16 @@
  *  Similar to argv_msg() but prefixes the messages being written with a
  *  given string.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write
- *  @param prefix  Valid pointer to the prefix string
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write
+ *  @param prefix    Valid pointer to the prefix string
  *
  */
 void
-argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix)
+argv_msg_prefix(const msglvl_t msglevel, const struct argv *a, const char *prefix)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s: %s", prefix, argv_str(a, &gc, 0));
+    msg(msglevel, "%s: %s", prefix, argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
src/openvpn/argv.h +2 -2
index 056fe31..969d7b1 100644
@@ -47,9 +47,9 @@
 
 struct argv argv_insert_head(const struct argv *a, const char *head);
 
-void argv_msg(const int msglev, const struct argv *a);
+void argv_msg(const msglvl_t msglevel, const struct argv *a);
 
-void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix);
+void argv_msg_prefix(const msglvl_t msglevel, const struct argv *a, const char *prefix);
 
 void argv_parse_cmd(struct argv *a, const char *s);
 
src/openvpn/buffer.c +1 -1
index 0f0d17e..c0b85b2 100644
@@ -1127,7 +1127,7 @@
 {
     if (buf && buf->len)
     {
-        int msglevel = D_ALIGN_DEBUG;
+        msglvl_t msglevel = D_ALIGN_DEBUG;
         const unsigned int u = (unsigned int)BPTR(buf);
 
         if (u & (PAYLOAD_ALIGN - 1))
src/openvpn/clinat.c +3 -3
index 48a2057..b49d4bb 100644
@@ -47,7 +47,7 @@
 }
 
 void
-print_client_nat_list(const struct client_nat_option_list *list, int msglevel)
+print_client_nat_list(const struct client_nat_option_list *list, msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     int i;
@@ -101,7 +101,7 @@
 void
 add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                               const char *network, const char *netmask, const char *foreign_network,
-                              int msglevel)
+                              msglvl_t msglevel)
 {
     struct client_nat_entry e;
     bool ok;
@@ -159,7 +159,7 @@
 #endif
 
 static void
-print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const int msglevel)
+print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
 
src/openvpn/clinat.h +2 -2
index abfa0b7..7d787e0 100644
@@ -54,11 +54,11 @@
 void copy_client_nat_option_list(struct client_nat_option_list *dest,
                                  const struct client_nat_option_list *src);
 
-void print_client_nat_list(const struct client_nat_option_list *list, int msglevel);
+void print_client_nat_list(const struct client_nat_option_list *list, msglvl_t msglevel);
 
 void add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                                    const char *network, const char *netmask,
-                                   const char *foreign_network, int msglevel);
+                                   const char *foreign_network, msglvl_t msglevel);
 
 void client_nat_transform(const struct client_nat_option_list *list, struct buffer *ipbuf,
                           const int direction);
src/openvpn/comp.c +1 -1
index 1a2e775..9d35141 100644
@@ -159,7 +159,7 @@
 #endif /* USE_COMP */
 
 bool
-check_compression_settings_valid(struct compress_options *info, int msglevel)
+check_compression_settings_valid(struct compress_options *info, msglvl_t msglevel)
 {
     /*
      * We also allow comp-stub-v2 here as it technically allows escaping of
src/openvpn/comp.h +3 -1
index 0354896..1717029 100644
@@ -84,12 +84,14 @@
            && info->alg != COMP_ALG_UNDEF;
 }
 
+#include "error.h"
+
 /**
  * Checks if the compression settings are valid. Takes into account the
  * flags of allow-compression and also the whether algorithms are compiled
  * in
  */
-bool check_compression_settings_valid(struct compress_options *info, int msglevel);
+bool check_compression_settings_valid(struct compress_options *info, msglvl_t msglevel);
 
 #ifdef USE_COMP
 #include "buffer.h"
src/openvpn/crypto.c +1 -1
index 1535c78..0e930d6 100644
@@ -1618,7 +1618,7 @@
 }
 
 int
-ascii2keydirection(int msglevel, const char *str)
+ascii2keydirection(msglvl_t msglevel, const char *str)
 {
     if (!str)
     {
src/openvpn/crypto.h +1 -1
index efd7f60..d69db59 100644
@@ -618,7 +618,7 @@
 
 void must_have_n_keys(const char *filename, const char *option, const struct key2 *key2, int n);
 
-int ascii2keydirection(int msglevel, const char *str);
+int ascii2keydirection(msglvl_t msglevel, const char *str);
 
 const char *keydirection2ascii(int kd, bool remote, bool humanreadable);
 
src/openvpn/dco.c +4 -4
index 823b4f9..2cf90af 100644
@@ -233,7 +233,7 @@
 }
 
 static bool
-dco_check_option_ce(const struct connection_entry *ce, int msglevel, int mode)
+dco_check_option_ce(const struct connection_entry *ce, msglvl_t msglevel, int mode)
 {
     if (ce->fragment)
     {
@@ -293,7 +293,7 @@
 }
 
 bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(msglvl_t msglevel, const struct options *o)
 {
     /* check if no dev name was specified at all. In the case,
      * later logic will most likely stop OpenVPN, so no need to
@@ -430,7 +430,7 @@
 }
 
 bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(msglvl_t msglevel, const struct options *o)
 {
     /* At this point the ciphers have already been normalised */
     if (o->enable_ncp_fallback
@@ -480,7 +480,7 @@
 }
 
 bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(msglvl_t msglevel, const struct options *o)
 {
     if (!o->use_peer_id)
     {
src/openvpn/dco.h +8 -8
index 59acb18..a362977 100644
@@ -55,7 +55,7 @@
  * @param msglevel      level to print messages to
  * @return              true if ovpn-dco is available, false otherwise
  */
-bool dco_available(int msglevel);
+bool dco_available(msglvl_t msglevel);
 
 
 /**
@@ -75,7 +75,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_option(int msglevel, const struct options *o);
+bool dco_check_option(msglvl_t msglevel, const struct options *o);
 
 /**
  * Check whether the options struct has any further option that is not supported
@@ -87,7 +87,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_startup_option(int msglevel, const struct options *o);
+bool dco_check_startup_option(msglvl_t msglevel, const struct options *o);
 
 /**
  * Check whether any of the options pushed by the server is not supported by
@@ -98,7 +98,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_pull_options(int msglevel, const struct options *o);
+bool dco_check_pull_options(msglvl_t msglevel, const struct options *o);
 
 /**
  * Initialize the DCO context
@@ -261,7 +261,7 @@
 typedef void *dco_context_t;
 
 static inline bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     return false;
 }
@@ -273,19 +273,19 @@
 }
 
 static inline bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
src/openvpn/dco_freebsd.c +1 -1
index 56a774d..b9f6bc7 100644
@@ -663,7 +663,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     struct if_clonereq ifcr;
     char *buf = NULL;
src/openvpn/dco_linux.c +2 -2
index 3b08f33..395a38f 100644
@@ -79,7 +79,7 @@
  * @return ID on success, negative error code on error
  */
 static int
-resolve_ovpn_netlink_id(int msglevel)
+resolve_ovpn_netlink_id(msglvl_t msglevel)
 {
     int ret;
     struct nl_sock *nl_sock = nl_socket_alloc();
@@ -1204,7 +1204,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0)
     {
src/openvpn/dco_win.c +1 -1
index 1dc5cf8..9e52859 100644
@@ -609,7 +609,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     /* try to open device by symbolic name */
     HANDLE h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
src/openvpn/dns.c +1 -1
index 5421004..efb888a 100644
@@ -200,7 +200,7 @@
 }
 
 bool
-dns_options_verify(int msglevel, const struct dns_options *o)
+dns_options_verify(msglvl_t msglevel, const struct dns_options *o)
 {
     const struct dns_server *server = o->servers ? o->servers : o->servers_prepull;
     while (server)
src/openvpn/dns.h +1 -1
index 6d97b40..6cd98f2 100644
@@ -166,7 +166,7 @@
  * @param   o           Pointer to the DNS options to validate
  * @return              True if no error was found
  */
-bool dns_options_verify(int msglevel, const struct dns_options *o);
+bool dns_options_verify(msglvl_t msglevel, const struct dns_options *o);
 
 /**
  * Makes a deep copy of the passed DNS options.
src/openvpn/env_set.c +1 -1
index 6c7df8e..2ae71ab 100644
@@ -209,7 +209,7 @@
 }
 
 void
-env_set_print(int msglevel, const struct env_set *es)
+env_set_print(msglvl_t msglevel, const struct env_set *es)
 {
     if (check_debug_level(msglevel))
     {
src/openvpn/env_set.h +1 -1
index 3973a4e..ddcfa14 100644
@@ -85,7 +85,7 @@
 
 const char *env_set_get(const struct env_set *es, const char *name);
 
-void env_set_print(int msglevel, const struct env_set *es);
+void env_set_print(msglvl_t msglevel, const struct env_set *es);
 
 /**
  * Write a struct env_set to a file. Each item on one line.
src/openvpn/error.c +15 -17
index 1b98235..58c2fd1 100644
@@ -48,12 +48,12 @@
 #endif
 
 /* Globals */
-unsigned int x_debug_level; /* GLOBAL */
+msglvl_t x_debug_level; /* GLOBAL */
 
 /* Mute state */
-static int mute_cutoff;   /* GLOBAL */
-static int mute_count;    /* GLOBAL */
-static int mute_category; /* GLOBAL */
+static int mute_cutoff;        /* GLOBAL */
+static int mute_count;         /* GLOBAL */
+static msglvl_t mute_category; /* GLOBAL */
 
 /*
  * Output mode priorities are as follows:
@@ -103,16 +103,14 @@
 bool
 set_debug_level(const int level, const unsigned int flags)
 {
-    const int ceiling = 15;
-
-    if (level >= 0 && level <= ceiling)
+    if (level >= 0 && level <= M_DEBUG_LEVEL)
     {
-        x_debug_level = level;
+        x_debug_level = (msglvl_t)level;
         return true;
     }
     else if (flags & SDL_CONSTRAIN)
     {
-        x_debug_level = constrain_int(level, 0, ceiling);
+        x_debug_level = (msglvl_t)constrain_int(level, 0, M_DEBUG_LEVEL);
         return true;
     }
     return false;
@@ -132,7 +130,7 @@
     }
 }
 
-int
+msglvl_t
 get_debug_level(void)
 {
     return x_debug_level;
@@ -190,7 +188,7 @@
  * Return a file to print messages to before syslog is opened.
  */
 FILE *
-msg_fp(const unsigned int flags)
+msg_fp(const msglvl_t flags)
 {
     FILE *fp = msgfp;
     if (!fp)
@@ -214,7 +212,7 @@
 int x_msg_line_num; /* GLOBAL */
 
 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const msglvl_t flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -235,7 +233,7 @@
 }
 
 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const msglvl_t flags, const char *format, va_list arglist)
 {
     struct gc_arena gc;
 #if SYSLOG_CAPABILITY
@@ -385,13 +383,13 @@
  * Apply muting filter.
  */
 bool
-dont_mute(unsigned int flags)
+dont_mute(msglvl_t flags)
 {
     bool ret = true;
     if (mute_cutoff > 0 && !(flags & M_NOMUTE))
     {
-        const int mute_level = DECODE_MUTE_LEVEL(flags);
-        if (mute_level > 0 && mute_level == mute_category)
+        const msglvl_t mute_level = DECODE_MUTE_LEVEL(flags);
+        if (mute_level == mute_category)
         {
             if (mute_count == mute_cutoff)
             {
@@ -750,7 +748,7 @@
  * Translate msg flags into a string
  */
 const char *
-msg_flags_string(const unsigned int flags, struct gc_arena *gc)
+msg_flags_string(const msglvl_t flags, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(16, gc);
     if (flags == M_INFO)
src/openvpn/error.h +27 -25

124 lines not on this page · raw message

src/openvpn/forward.c +3 -2
index e82b544..f342958 100644
@@ -373,7 +373,8 @@
 #endif
 
 bool
-send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel)
+send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                   msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     bool stat;
@@ -400,7 +401,7 @@
 }
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     if (c->c2.tls_multi)
     {
src/openvpn/forward.h +3 -2
index 79d0f8b..a575faf 100644
@@ -285,7 +285,7 @@
  * @param str        - The message to be sent
  * @param msglevel   - Message level to use for logging
  */
-bool send_control_channel_string(struct context *c, const char *str, int msglevel);
+bool send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel);
 
 /*
  * Send a string to remote over the TLS control channel.
@@ -303,7 +303,8 @@
  * @param msglevel   - Message level to use for logging
  */
 
-bool send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel);
+bool send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                        msglvl_t msglevel);
 
 
 /**
src/openvpn/init.c +1 -1
index 24aebc0..f8a0fee 100644
@@ -4282,7 +4282,7 @@
 }
 
 void
-management_show_net_callback(void *arg, const int msglevel)
+management_show_net_callback(void *arg, const msglvl_t msglevel)
 {
 #ifdef _WIN32
     show_routes(msglevel);
src/openvpn/init.h +1 -1
index a807874..e89615b 100644
@@ -136,7 +136,7 @@
 
 void close_management(void);
 
-void management_show_net_callback(void *arg, const int msglevel);
+void management_show_net_callback(void *arg, const msglvl_t msglevel);
 
 #endif
 
src/openvpn/manage.c +1 -1
index 4f37bd2..5a41a0f 100644
@@ -1484,7 +1484,7 @@
         }
         else
         {
-            msg(M_CLIENT, "SUCCESS: verb=%d", get_debug_level());
+            msg(M_CLIENT, "SUCCESS: verb=%u", get_debug_level());
         }
     }
     else if (streq(p[0], "mute"))
src/openvpn/manage.h +1 -1
index 7c189ba..bff96d3 100644
@@ -176,7 +176,7 @@
     unsigned int flags;
 
     void (*status)(void *arg, const int version, struct status_output *so);
-    void (*show_net)(void *arg, const int msglevel);
+    void (*show_net)(void *arg, const msglvl_t msglevel);
     int (*kill_by_cn)(void *arg, const char *common_name);
     int (*kill_by_addr)(void *arg, const in_addr_t addr, const int port, const int proto);
     void (*delete_event)(void *arg, event_t event);
src/openvpn/mtu.c +2 -2
index 1e021e3..66f81a6 100644
@@ -187,7 +187,7 @@
 }
 
 void
-frame_print(const struct frame *frame, int level, const char *prefix)
+frame_print(const struct frame *frame, msglvl_t msglevel, const char *prefix)
 {
     struct gc_arena gc = gc_new();
     struct buffer out = alloc_buf_gc(256, &gc);
@@ -208,7 +208,7 @@
     buf_printf(&out, " ET:%d", frame->extra_tun);
     buf_printf(&out, " ]");
 
-    msg(level, "%s", out.data);
+    msg(msglevel, "%s", out.data);
     gc_free(&gc);
 }
 
src/openvpn/mtu.h +1 -1
index c092461..3bbff6f 100644
@@ -181,7 +181,7 @@
  * Function prototypes.
  */
 
-void frame_print(const struct frame *frame, int level, const char *prefix);
+void frame_print(const struct frame *frame, msglvl_t msglevel, const char *prefix);
 
 void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af);
 
src/openvpn/multi.c +1 -1
index 579eeea..3877f8d 100644
@@ -3321,7 +3321,7 @@
     }
     else
     {
-        int msglevel = D_DCO;
+        msglvl_t msglevel = D_DCO;
         if (dco->dco_message_type == OVPN_CMD_DEL_PEER
             && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
         {
src/openvpn/options.c +52 -48

330 lines not on this page · raw message

src/openvpn/options.h +6 -6
index bb2c052..a737711 100644
@@ -822,7 +822,7 @@
     struct pull_filter *tail;
 };
 
-void parse_argv(struct options *options, const int argc, char *argv[], const int msglevel,
+void parse_argv(struct options *options, const int argc, char *argv[], const msglvl_t msglevel,
                 const unsigned int permission_mask, unsigned int *option_types_found,
                 struct env_set *es);
 
@@ -888,7 +888,7 @@
 
 void options_detach(struct options *o);
 
-void options_server_import(struct options *o, const char *filename, int msglevel,
+void options_server_import(struct options *o, const char *filename, msglvl_t msglevel,
                            unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
@@ -897,13 +897,13 @@
 void rol_check_alloc(struct options *options);
 
 int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num,
-               int msglevel, struct gc_arena *gc);
+               msglvl_t msglevel, struct gc_arena *gc);
 
 /*
  * parse/print topology coding
  */
 
-int parse_topology(const char *str, const int msglevel);
+int parse_topology(const char *str, const msglvl_t msglevel);
 
 const char *print_topology(const int topology);
 
@@ -917,11 +917,11 @@
 
 int auth_retry_get(void);
 
-bool auth_retry_set(const int msglevel, const char *option);
+bool auth_retry_set(const msglvl_t msglevel, const char *option);
 
 const char *auth_retry_print(void);
 
-void options_string_import(struct options *options, const char *config, const int msglevel,
+void options_string_import(struct options *options, const char *config, const msglvl_t msglevel,
                            const unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
src/openvpn/options_util.c +4 -4
index a351967..125d47c 100644
@@ -117,7 +117,7 @@
 }
 
 int
-positive_atoi(const char *str, int msglevel)
+positive_atoi(const char *str, msglvl_t msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -132,7 +132,7 @@
 }
 
 bool
-positive_atoll(const char *str, int64_t *value, const char *name, int msglevel)
+positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel)
 {
     char *endptr;
     long long ll = strtoll(str, &endptr, 10);
@@ -148,7 +148,7 @@
 }
 
 int
-atoi_warn(const char *str, int msglevel)
+atoi_warn(const char *str, msglvl_t msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -168,7 +168,7 @@
 #endif
 
 bool
-atoi_constrained(const char *str, int *value, const char *name, int min, int max, int msglevel)
+atoi_constrained(const char *str, int *value, const char *name, int min, int max, msglvl_t msglevel)
 {
     ASSERT(min < max);
 
src/openvpn/options_util.h +4 -4
index 45417d9..1492eef 100644
@@ -37,7 +37,7 @@
  * Converts a str to a positive number if the string represents a postive
  * integer number. Otherwise print a warning with msglevel and return 0
  */
-int positive_atoi(const char *str, int msglevel);
+int positive_atoi(const char *str, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -48,13 +48,13 @@
  *
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
-bool positive_atoll(const char *str, int64_t *value, const char *name, int msglevel);
+bool positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
  * integer number. Otherwise print a warning with \p msglevel and return 0
  */
-int atoi_warn(const char *str, int msglevel);
+int atoi_warn(const char *str, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -66,7 +66,7 @@
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
 bool atoi_constrained(const char *str, int *value, const char *name, int min, int max,
-                      int msglevel);
+                      msglvl_t msglevel);
 
 /**
  * Filter an option line by all pull filters.
src/openvpn/packet_id.c +5 -4
index 0b33c9c..880eee1 100644
@@ -53,15 +53,15 @@
 #define SEQ_EXPIRED ((time_t)1)
 
 #ifdef ENABLE_DEBUG
-static void packet_id_debug_print(int msglevel, const struct packet_id_rec *p,
+static void packet_id_debug_print(msglvl_t msglevel, const struct packet_id_rec *p,
                                   const struct packet_id_net *pin, const char *message,
                                   packet_id_print_type value);
 
 #endif /* ENABLE_DEBUG */
 
 static inline void
-packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
-                const char *message, uint64_t value)
+packet_id_debug(msglvl_t msglevel, const struct packet_id_rec *p,
+                const struct packet_id_net *pin, const char *message, uint64_t value)
 {
 #ifdef ENABLE_DEBUG
     if (unlikely(check_debug_level(msglevel)))
@@ -578,7 +578,8 @@
 #ifdef ENABLE_DEBUG
 
 static void
-packet_id_debug_print(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
+packet_id_debug_print(msglvl_t msglevel, const struct packet_id_rec *p,
+                      const struct packet_id_net *pin,
                       const char *message, packet_id_print_type value)
 {
     struct gc_arena gc = gc_new();
src/openvpn/pkcs11.c +3 -3
index d9c16d9..16149ca 100644
@@ -77,10 +77,10 @@
 #endif
 };
 
-static unsigned
+static msglvl_t
 _pkcs11_msg_pkcs112openvpn(const unsigned flags)
 {
-    unsigned openvpn_flags;
+    msglvl_t openvpn_flags;
 
     switch (flags)
     {
@@ -117,7 +117,7 @@
 }
 
 static unsigned
-_pkcs11_msg_openvpn2pkcs11(const unsigned flags)
+_pkcs11_msg_openvpn2pkcs11(const msglvl_t flags)
 {
     unsigned pkcs11_flags;
 
src/openvpn/plugin.c +4 -4
index ea76a08..a105058 100644
@@ -50,7 +50,7 @@
 static struct plugin_common *static_plugin_common = NULL; /* GLOBAL */
 
 static void
-plugin_show_string_array(int msglevel, const char *name, const char *array[])
+plugin_show_string_array(msglvl_t msglevel, const char *name, const char *array[])
 {
     int i;
     for (i = 0; array[i]; ++i)
@@ -63,7 +63,7 @@
 }
 
 static void
-plugin_show_args_env(int msglevel, const char *argv[], const char *envp[])
+plugin_show_args_env(msglvl_t msglevel, const char *argv[], const char *envp[])
 {
     if (check_debug_level(msglevel))
     {
@@ -184,7 +184,7 @@
 
 #ifndef ENABLE_SMALL
 void
-plugin_option_list_print(const struct plugin_option_list *list, int msglevel)
+plugin_option_list_print(const struct plugin_option_list *list, msglvl_t msglevel)
 {
     int i;
     struct gc_arena gc = gc_new();
@@ -995,7 +995,7 @@
 
 #ifdef ENABLE_DEBUG
 void
-plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr)
+plugin_return_print(const msglvl_t msglevel, const char *prefix, const struct plugin_return *pr)
 {
     int i;
     msg(msglevel, "PLUGIN_RETURN_PRINT %s", prefix);
src/openvpn/plugin.h +2 -2
index 63999b6..81d3739 100644
@@ -111,7 +111,7 @@
 bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc);
 
 #ifndef ENABLE_SMALL
-void plugin_option_list_print(const struct plugin_option_list *list, int msglevel);
+void plugin_option_list_print(const struct plugin_option_list *list, msglvl_t msglevel);
 
 #endif
 
@@ -136,7 +136,7 @@
 void plugin_return_free(struct plugin_return *pr);
 
 #ifdef ENABLE_DEBUG
-void plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr);
+void plugin_return_print(const msglvl_t msglevel, const char *prefix, const struct plugin_return *pr);
 
 #endif
 
src/openvpn/pool.c +1 -1
index fde6cea..28ddd2c 100644
@@ -114,7 +114,7 @@
  * Verify start/end range
  */
 bool
-ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end)
+ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end)
 {
     struct gc_arena gc = gc_new();
     bool ret = true;
src/openvpn/pool.h +1 -1
index 6cecef0..36e9fca 100644
@@ -78,7 +78,7 @@
 
 void ifconfig_pool_free(struct ifconfig_pool *pool);
 
-bool ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end);
+bool ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end);
 
 ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local,
                                            in_addr_t *remote, struct in6_addr *remote_ipv6,
src/openvpn/proto.c +1 -1
index 34b3378..ab77887 100644
@@ -183,7 +183,7 @@
             int hlen;
             int totlen;
             const char *msgstr = "PACKET SIZE INFO";
-            unsigned int msglevel = D_PACKET_TRUNC_DEBUG;
+            msglvl_t msglevel = D_PACKET_TRUNC_DEBUG;
 
             if (BLEN(&buf) < (int)sizeof(struct openvpn_iphdr))
             {
src/openvpn/push.c +7 -7
index 671b015..e7fc50c 100644
@@ -373,8 +373,8 @@
  *
  * @return true on success, false on failure.
  */
-static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel,
-                            const char *fmt, ...)
+static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                            msglvl_t msglevel, const char *fmt, ...)
 #ifdef __GNUC__
 #if __USE_MINGW_ANSI_STDIO
     __attribute__((format(gnu_printf, 4, 5)))
@@ -857,7 +857,7 @@
 
 static void
 push_option_ex(struct gc_arena *gc, struct push_list *push_list, const char *opt, bool enable,
-               int msglevel)
+               msglvl_t msglevel)
 {
     if (!string_class(opt, CC_ANY, CC_COMMA))
     {
@@ -885,7 +885,7 @@
 }
 
 void
-push_option(struct options *o, const char *opt, int msglevel)
+push_option(struct options *o, const char *opt, msglvl_t msglevel)
 {
     push_option_ex(&o->gc, &o->push_list, opt, true, msglevel);
 }
@@ -906,7 +906,7 @@
 }
 
 void
-push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc)
+push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc)
 {
     const char **argv = make_extended_arg_array(p, false, gc);
     char *opt = print_argv(argv, gc, 0);
@@ -914,8 +914,8 @@
 }
 
 static bool
-push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel, const char *format,
-                ...)
+push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                msglvl_t msglevel, const char *format, ...)
 {
     va_list arglist;
     char tmp[256] = { 0 };
src/openvpn/push.h +2 -2
index 8ffd0c2..6b3275e 100644
@@ -99,9 +99,9 @@
 
 void clone_push_list(struct options *o);
 
-void push_option(struct options *o, const char *opt, int msglevel);
+void push_option(struct options *o, const char *opt, msglvl_t msglevel);
 
-void push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc);
+void push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc);
 
 void push_reset(struct options *o);
 
src/openvpn/route.c +13 -13
index d3d2954..156a99e 100644
@@ -1228,28 +1228,28 @@
 }
 
 static void
-print_route_option(const struct route_option *ro, int level)
+print_route_option(const struct route_option *ro, msglvl_t msglevel)
 {
-    msg(level, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
+    msg(msglevel, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
         show_opt(ro->gateway), show_opt(ro->metric));
 }
 
 void
-print_route_options(const struct route_option_list *rol, int level)
+print_route_options(const struct route_option_list *rol, msglvl_t msglevel)
 {
     struct route_option *ro;
     if (rol->flags & RG_ENABLE)
     {
-        msg(level, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
+        msg(msglevel, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
     }
     for (ro = rol->routes; ro; ro = ro->next)
     {
-        print_route_option(ro, level);
+        print_route_option(ro, msglevel);
     }
 }
 
 void
-print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi,
                       const struct route_ipv6_gateway_info *rgi6)
 {
     struct gc_arena gc = gc_new();
@@ -1323,23 +1323,23 @@
 #endif /* ifndef ENABLE_SMALL */
 
 static void
-print_route(const struct route_ipv4 *r, int level)
+print_route(const struct route_ipv4 *r, msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     if (r->flags & RT_DEFINED)
     {
-        msg(level, "%s", route_string(r, &gc));
+        msg(msglevel, "%s", route_string(r, &gc));
     }
     gc_free(&gc);
 }
 
 void
-print_routes(const struct route_list *rl, int level)
+print_routes(const struct route_list *rl, msglvl_t msglevel)
 {
     struct route_ipv4 *r;
     for (r = rl->routes; r; r = r->next)
     {
-        print_route(r, level);
+        print_route(r, msglevel);
     }
 }
 
@@ -3067,18 +3067,18 @@
  * Show current routing table
  */
 void
-show_routes(int msglev)
+show_routes(msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
 
     const MIB_IPFORWARDTABLE *rt = get_windows_routing_table(&gc);
 
-    msg(msglev, "SYSTEM ROUTING TABLE");
+    msg(msglevel, "SYSTEM ROUTING TABLE");
     if (rt)
     {
         for (DWORD i = 0; i < rt->dwNumEntries; ++i)
         {
-            msg(msglev, "%s", format_route_entry(&rt->table[i], &gc));
+            msg(msglevel, "%s", format_route_entry(&rt->table[i], &gc));
         }
     }
     gc_free(&gc);
src/openvpn/route.h +4 -4
index 9b6a47e..c5006ae 100644
@@ -356,7 +356,7 @@
 void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi, const struct in6_addr *dest,
                               openvpn_net_ctx_t *ctx);
 
-void print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+void print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi,
                            const struct route_ipv6_gateway_info *rgi6);
 
 /*
@@ -371,15 +371,15 @@
 int test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi);
 
 #ifndef ENABLE_SMALL
-void print_route_options(const struct route_option_list *rol, int level);
+void print_route_options(const struct route_option_list *rol, msglvl_t msglevel);
 
 #endif
 
-void print_routes(const struct route_list *rl, int level);
+void print_routes(const struct route_list *rl, msglvl_t msglevel);
 
 #ifdef _WIN32
 
-void show_routes(int msglev);
+void show_routes(msglvl_t msglevel);
 
 bool test_routes(const struct route_list *rl, const struct tuntap *tt);
 
src/openvpn/run_command.c +1 -1
index 4a1ef22..a0c9484 100644
@@ -107,7 +107,7 @@
 
 #ifndef WIN32
 bool
-openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel)
+openvpn_waitpid_check(pid_t pid, const char *msg_prefix, msglvl_t msglevel)
 {
     if (pid == 0)
     {
src/openvpn/run_command.h +5 -5
index afd1b88..234055e 100644
@@ -71,13 +71,13 @@
  * This function is currently not implemented for Windows as the helper
  * macros used by this function are not available.
  *
- * @param pid               pid of the process to be checked
+ * @param pid            pid of the process to be checked
  * @param msg_prefix     prefixed of the message that be printed
- * @param msglevel          msglevel of the messages to be printed
- * @return                  true if the process is still running, false if
- *                          an error condition occurred
+ * @param msglevel       msglevel of the messages to be printed
+ * @return               true if the process is still running, false if
+ *                       an error condition occurred
  */
-bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel);
+bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, msglvl_t msglevel);
 
 #endif
 
src/openvpn/sig.c +1 -1
index ecea635..42ad823 100644
@@ -287,7 +287,7 @@
 }
 
 void
-print_signal(const struct signal_info *si, const char *title, int msglevel)
+print_signal(const struct signal_info *si, const char *title, msglvl_t msglevel)
 {
     if (si)
     {
src/openvpn/sig.h +1 -1
index 7e5dd9f..b5d81fc 100644
@@ -66,7 +66,7 @@
 
 void restore_signal_state(void);
 
-void print_signal(const struct signal_info *si, const char *title, int msglevel);
+void print_signal(const struct signal_info *si, const char *title, msglvl_t msglevel);
 
 void print_status(struct context *c, struct status_output *so);
 
src/openvpn/socket.c +4 -3
index 248c690..69445d9 100644
@@ -83,7 +83,7 @@
 static int
 get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname, void *network,
                  unsigned int *netbits, int resolve_retry_seconds, struct signal_info *sig_info,
-                 int msglevel)
+                 msglvl_t msglevel)
 {
     char *endp, *sep, *var_host = NULL;
     struct addrinfo *ai = NULL;
@@ -216,7 +216,8 @@
 }
 
 bool
-get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
+get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
+              msglvl_t msglevel)
 {
     if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostname, network, netbits, 0, NULL, msglevel)
         < 0)
@@ -1521,7 +1522,7 @@
 linksock_print_addr(struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
-    const int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
+    const msglvl_t msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
 
     /* print local address */
     if (sock->bind_local)
src/openvpn/socket_util.c +3 -3
index 9b7312d..fa566e7 100644
@@ -541,7 +541,7 @@
     struct addrinfo hints;
     int status;
     struct signal_info sigrec = { 0 };
-    int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
+    msglvl_t msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
     struct gc_arena gc = gc_new();
     const char *print_hostname;
     const char *print_servname;
@@ -604,7 +604,7 @@
         int resolve_retries =
             (flags & GETADDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) / fail_wait_interval);
         const char *fmt;
-        int level = 0;
+        msglvl_t level = 0;
 
         /* this is not a numeric IP, therefore force resolution using the
          * provided ai_family */
@@ -739,7 +739,7 @@
 done:
     if (sig_info && sig_info->signal_received)
     {
-        int level = 0;
+        msglvl_t level = 0;
         if (flags & GETADDR_FATAL_ON_SIGNAL)
         {
             level = M_FATAL;
src/openvpn/socket_util.h +1 -1
index 361edff..ada52a4 100644
@@ -142,7 +142,7 @@
  * Translate an IPv6 addr or hostname from string form to in6_addr
  */
 bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
-                   int msglevel);
+                   msglvl_t msglevel);
 
 int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname,
                         int resolve_retry_seconds, struct signal_info *sig_info, int ai_family,
src/openvpn/ssl_verify_backend.h +2 -2
index a0559c9..2bad3eb 100644
@@ -193,8 +193,8 @@
  * @param gc            Garbage collection arena for temp data
  *
  */
-void x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
-                    struct gc_arena *gc);
+void x509_track_add(const struct x509_track **ll_head, const char *name,
+                    msglvl_t msglevel, struct gc_arena *gc);
 
 /*
  * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_mbedtls.c +1 -1
index a2c702d..0915e3e 100644
@@ -359,7 +359,7 @@
 }
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, msglvl_t msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/ssl_verify_openssl.c +1 -1
index 122101c..12aae62 100644
@@ -414,7 +414,7 @@
  */
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, msglvl_t msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/status.c +2 -3
index fbd2168..1e1e3fb 100644
@@ -235,14 +235,13 @@
 
         if (so->msglevel >= 0 && !so->errors)
         {
-            msg(so->msglevel, "%s", buf);
+            msg((msglvl_t)so->msglevel, "%s", buf);
         }
 
         if (so->fd >= 0 && !so->errors)
         {
-            int len;
             strcat(buf, "\n");
-            len = strlen(buf);
+            size_t len = strlen(buf);
             if (len > 0)
             {
                 if (write(so->fd, buf, len) != len)
src/openvpn/status.h +1 -0
index 0c7a869..25e1663 100644
@@ -53,6 +53,7 @@
 
     char *filename;
     int fd;
+    /* NB: -1 is used to indicate that output should only go to the file */
     int msglevel;
     const struct virtual_output *vout;
 
src/openvpn/tun.c +27 -27

146 lines not on this page · raw message

src/openvpn/tun.h +2 -2
index 06fc729..6562c22 100644
@@ -445,9 +445,9 @@
 DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count,
                           in_addr_t *netmask);
 
-void show_tap_win_adapters(int msglev, int warnlev);
+void show_tap_win_adapters(msglvl_t msglevel, msglvl_t warnlevel);
 
-void show_adapters(int msglev);
+void show_adapters(msglvl_t msglevel);
 
 void tap_allow_nonadmin_access(const char *dev_node);
 
tests/unit_tests/openvpn/mock_msg.c +9 -9
index 603520b..69d2d1d 100644
@@ -38,8 +38,8 @@
 #include "error.h"
 #include "mock_msg.h"
 
-unsigned int x_debug_level = 0; /* Default to (almost) no debugging output */
-unsigned int print_x_debug_level = 0;
+msglvl_t x_debug_level = 0; /* Default to (almost) no debugging output */
+msglvl_t print_x_debug_level = 0;
 
 bool fatal_error_triggered = false;
 
@@ -47,31 +47,31 @@
 
 
 void
-mock_set_debug_level(int level)
+mock_set_debug_level(msglvl_t level)
 {
     x_debug_level = level;
 }
 
-int
+msglvl_t
 mock_get_debug_level(void)
 {
     return x_debug_level;
 }
 
 void
-mock_set_print_debug_level(int level)
+mock_set_print_debug_level(msglvl_t level)
 {
     print_x_debug_level = level;
 }
 
-int
+msglvl_t
 get_debug_level(void)
 {
     return x_debug_level;
 }
 
 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const msglvl_t flags, const char *format, va_list arglist)
 {
     if (flags & M_FATAL)
     {
@@ -89,7 +89,7 @@
 }
 
 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const msglvl_t flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -128,7 +128,7 @@
 }
 
 bool
-dont_mute(unsigned int flags)
+dont_mute(msglvl_t flags)
 {
     return true;
 }
tests/unit_tests/openvpn/mock_msg.h +3 -5
index f4ebc23..6dddf0b 100644
@@ -28,17 +28,15 @@
  * this function from your test driver to increase debug output when you
  * need debug output.
  */
-void mock_set_debug_level(int level);
+void mock_set_debug_level(msglvl_t level);
 
 #define MOCK_MSG_BUF 2048
 
 extern bool fatal_error_triggered;
 extern char mock_msg_buf[MOCK_MSG_BUF];
 
-void mock_set_debug_level(int level);
+msglvl_t mock_get_debug_level(void);
 
-int mock_get_debug_level(void);
-
-void mock_set_print_debug_level(int level);
+void mock_set_print_debug_level(msglvl_t level);
 
 #endif /* MOCK_MSG */
tests/unit_tests/openvpn/mock_ssl_dependencies.c +1 -1
index 7333c47..f2fa93a 100644
@@ -38,7 +38,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_argv.c +1 -1
index a65857b..a04fabc 100644
@@ -23,7 +23,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  msglvl_t msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_misc.c +2 -2
index 3433b73..5260a31 100644
@@ -348,8 +348,8 @@
     assert_false(valid_integer("-2147483653", false));
 
 
-    int msglevel = D_LOW;
-    int saved_log_level = mock_get_debug_level();
+    msglvl_t msglevel = D_LOW;
+    msglvl_t saved_log_level = mock_get_debug_level();
     mock_set_debug_level(D_LOW);
 
     /* check happy path */
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
index 9ba6cfc..d568865 100644
@@ -59,7 +59,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_pkt.c +1 -1
index 5122766..b6c612b 100644
@@ -45,7 +45,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_push_update_msg.c +2 -2
index 87329b1..8a5beeb 100644
@@ -111,7 +111,7 @@
 
 #ifndef ENABLE_MANAGEMENT
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     return true;
 }
@@ -120,7 +120,7 @@
 int i;
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     if (res && res[i] && strcmp(res[i], str))
     {
tests/unit_tests/openvpn/test_socket.c +1 -1
index 2da2529..7f740ac 100644
@@ -59,7 +59,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_tls_crypt.c +1 -1
index 532bfcd..44d51fe 100644
@@ -98,7 +98,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  msglvl_t msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_user_pass.c +1 -1
index 460b37f..32ec59f 100644
@@ -73,7 +73,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
#14 lore raw

[Openvpn-devel] [PATCH applied] Re: Introduce msglvl_t to unify msglevel type handling

Huge patch, small actual change - turning all "int" msglevel uses (except one) into "unsigned int". To make this somewhat nicer to the eye, hide "unsiged int" in "msglvl_t" (also this makes it very clear what type a "msglevel" is supposed to have).

Stared long and hard at the diff, fed to GHA and t_server testbed for "ok, so what did I overlook?" testing. All green.

Your patch has been applied to the master branch.

commit cc8cd311749dc90bb056cfedd9129677090bc7b0

Author: Frank Lichtenheld
Date:   Wed Sep 17 19:04:19 2025 +0200
     Introduce msglvl_t to unify msglevel type handling

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1110
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg33028.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#15 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: Introduce msglvl_t to unify msglevel type handling

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email )

Change subject: Introduce msglvl_t to unify msglevel type handling
......................................................................

Patch Set 16:

(1 comment)

File src/openvpn/error.c:

http://gerrit.openvpn.net/c/openvpn/+/1110/comment/e38154f9_4a81f5bc :
PS16, Line 104: set_debug_level(const int level, const unsigned int flags)
why not turning this into msglvl_t too?
I see it normally gets passed o->verbosity, but it could also be turned to msglvl_t as well since it never gets assigned a negative number.

The only situation to check is manage.c:1467. The mgmt interface technically accepts "verb -1", but it is a bogus case. We could force it to be positive as well.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 16
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 18 Sep 2025 08:13:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#16 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: Introduce msglvl_t to unify msglevel type handling

In reply to a message not in the archive

Attention is currently required from: ordex, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email )

Change subject: Introduce msglvl_t to unify msglevel type handling
......................................................................

Patch Set 16:

(1 comment)

File src/openvpn/error.c:

http://gerrit.openvpn.net/c/openvpn/+/1110/comment/e7d1179f_51d3b84a :
PS16, Line 104: set_debug_level(const int level, const unsigned int flags)

Quoted 1 line

why not turning this into msglvl_t too? […]

I considered it, but then decided to leave it as is. I had to draw a boundary somewhere. We could definitely change it in a separate commit but this one is big enough as it is.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 16
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Thu, 18 Sep 2025 09:44:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment

#17 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: Introduce msglvl_t to unify msglevel type handling

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email )

Change subject: Introduce msglvl_t to unify msglevel type handling
......................................................................

Patch Set 16: Code-Review+2

(2 comments)

Patchset:

PS16:
LGTM

File src/openvpn/error.c:

http://gerrit.openvpn.net/c/openvpn/+/1110/comment/adb8b041_da6e06cc :
PS16, Line 104: set_debug_level(const int level, const unsigned int flags)

Quoted 1 line

I considered it, but then decided to leave it as is. I had to draw a boundary somewhere. […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 16
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 18 Sep 2025 12:08:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment

#18 lore raw

[Openvpn-devel] [L] Change in openvpn[master]: Introduce msglvl_t to unify msglevel type handling

In reply to a message not in the archive

cron2 has uploaded a new patch set (#17) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2, Code-Review+2 by ordex

Change subject: Introduce msglvl_t to unify msglevel type handling
......................................................................

Introduce msglvl_t to unify msglevel type handling

msglevel was definitely unsigned as the first argument to msg(), but many parts of the code had it as signed. So this produced a LOT of warnings when enabling -Wsign-conversion.

Introduce a msglvl_t typedef and switch all users to it. This includes any values that are stored in the msglevel field, including debug level and mute level.

There is one exception in struct status_output where -1 is a valid value in the API. Only positive values are translated into standard message levels.

Change-Id Id492cb774c6d022d06bb3cf5fec2a4bdd410e619

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1110
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg33028.html

---
M src/openvpn/argv.c
M src/openvpn/argv.h
M src/openvpn/buffer.c
M src/openvpn/clinat.c
M src/openvpn/clinat.h
M src/openvpn/comp.c
M src/openvpn/comp.h
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/dco.c
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dns.c
M src/openvpn/dns.h
M src/openvpn/env_set.c
M src/openvpn/env_set.h
M src/openvpn/error.c
M src/openvpn/error.h
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/manage.c
M src/openvpn/manage.h
M src/openvpn/mtu.c
M src/openvpn/mtu.h
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/packet_id.c
M src/openvpn/pkcs11.c
M src/openvpn/plugin.c
M src/openvpn/plugin.h
M src/openvpn/pool.c
M src/openvpn/pool.h
M src/openvpn/proto.c
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/route.c
M src/openvpn/route.h
M src/openvpn/run_command.c
M src/openvpn/run_command.h
M src/openvpn/sig.c
M src/openvpn/sig.h
M src/openvpn/socket.c
M src/openvpn/socket_util.c
M src/openvpn/socket_util.h
M src/openvpn/ssl_verify_backend.h
M src/openvpn/ssl_verify_mbedtls.c
M src/openvpn/ssl_verify_openssl.c
M src/openvpn/status.c
M src/openvpn/status.h
M src/openvpn/tun.c
M src/openvpn/tun.h
M tests/unit_tests/openvpn/mock_msg.c
M tests/unit_tests/openvpn/mock_msg.h
M tests/unit_tests/openvpn/mock_ssl_dependencies.c M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_push_update_msg.c M tests/unit_tests/openvpn/test_socket.c
M tests/unit_tests/openvpn/test_tls_crypt.c M tests/unit_tests/openvpn/test_user_pass.c

69 files changed, 283 insertions(+), 275 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/1110/17

src/openvpn/argv.c +9 -9
index 903fc0a..79b541a 100644
@@ -235,14 +235,14 @@
 /**
  *  Write the arguments stored in a struct argv via the msg() command.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write.
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write.
  */
 void
-argv_msg(const int msglev, const struct argv *a)
+argv_msg(const msglvl_t msglevel, const struct argv *a)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s", argv_str(a, &gc, 0));
+    msg(msglevel, "%s", argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
@@ -250,16 +250,16 @@
  *  Similar to argv_msg() but prefixes the messages being written with a
  *  given string.
  *
- *  @param msglev  Integer with the message level used by msg().
- *  @param a       Valid pointer to the struct argv with the arguments to write
- *  @param prefix  Valid pointer to the prefix string
+ *  @param msglevel  Integer with the message level used by msg().
+ *  @param a         Valid pointer to the struct argv with the arguments to write
+ *  @param prefix    Valid pointer to the prefix string
  *
  */
 void
-argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix)
+argv_msg_prefix(const msglvl_t msglevel, const struct argv *a, const char *prefix)
 {
     struct gc_arena gc = gc_new();
-    msg(msglev, "%s: %s", prefix, argv_str(a, &gc, 0));
+    msg(msglevel, "%s: %s", prefix, argv_str(a, &gc, 0));
     gc_free(&gc);
 }
 
src/openvpn/argv.h +2 -2
index 056fe31..969d7b1 100644
@@ -47,9 +47,9 @@
 
 struct argv argv_insert_head(const struct argv *a, const char *head);
 
-void argv_msg(const int msglev, const struct argv *a);
+void argv_msg(const msglvl_t msglevel, const struct argv *a);
 
-void argv_msg_prefix(const int msglev, const struct argv *a, const char *prefix);
+void argv_msg_prefix(const msglvl_t msglevel, const struct argv *a, const char *prefix);
 
 void argv_parse_cmd(struct argv *a, const char *s);
 
src/openvpn/buffer.c +1 -1
index 0f0d17e..c0b85b2 100644
@@ -1127,7 +1127,7 @@
 {
     if (buf && buf->len)
     {
-        int msglevel = D_ALIGN_DEBUG;
+        msglvl_t msglevel = D_ALIGN_DEBUG;
         const unsigned int u = (unsigned int)BPTR(buf);
 
         if (u & (PAYLOAD_ALIGN - 1))
src/openvpn/clinat.c +3 -3
index 48a2057..b49d4bb 100644
@@ -47,7 +47,7 @@
 }
 
 void
-print_client_nat_list(const struct client_nat_option_list *list, int msglevel)
+print_client_nat_list(const struct client_nat_option_list *list, msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     int i;
@@ -101,7 +101,7 @@
 void
 add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                               const char *network, const char *netmask, const char *foreign_network,
-                              int msglevel)
+                              msglvl_t msglevel)
 {
     struct client_nat_entry e;
     bool ok;
@@ -159,7 +159,7 @@
 #endif
 
 static void
-print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const int msglevel)
+print_pkt(struct openvpn_iphdr *iph, const char *prefix, const int direction, const msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
 
src/openvpn/clinat.h +2 -2
index abfa0b7..7d787e0 100644
@@ -54,11 +54,11 @@
 void copy_client_nat_option_list(struct client_nat_option_list *dest,
                                  const struct client_nat_option_list *src);
 
-void print_client_nat_list(const struct client_nat_option_list *list, int msglevel);
+void print_client_nat_list(const struct client_nat_option_list *list, msglvl_t msglevel);
 
 void add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type,
                                    const char *network, const char *netmask,
-                                   const char *foreign_network, int msglevel);
+                                   const char *foreign_network, msglvl_t msglevel);
 
 void client_nat_transform(const struct client_nat_option_list *list, struct buffer *ipbuf,
                           const int direction);
src/openvpn/comp.c +1 -1
index 1a2e775..9d35141 100644
@@ -159,7 +159,7 @@
 #endif /* USE_COMP */
 
 bool
-check_compression_settings_valid(struct compress_options *info, int msglevel)
+check_compression_settings_valid(struct compress_options *info, msglvl_t msglevel)
 {
     /*
      * We also allow comp-stub-v2 here as it technically allows escaping of
src/openvpn/comp.h +3 -1
index 0354896..1717029 100644
@@ -84,12 +84,14 @@
            && info->alg != COMP_ALG_UNDEF;
 }
 
+#include "error.h"
+
 /**
  * Checks if the compression settings are valid. Takes into account the
  * flags of allow-compression and also the whether algorithms are compiled
  * in
  */
-bool check_compression_settings_valid(struct compress_options *info, int msglevel);
+bool check_compression_settings_valid(struct compress_options *info, msglvl_t msglevel);
 
 #ifdef USE_COMP
 #include "buffer.h"
src/openvpn/crypto.c +1 -1
index 4c0f684..0abcd7f 100644
@@ -1609,7 +1609,7 @@
 }
 
 int
-ascii2keydirection(int msglevel, const char *str)
+ascii2keydirection(msglvl_t msglevel, const char *str)
 {
     if (!str)
     {
src/openvpn/crypto.h +1 -1
index efd7f60..d69db59 100644
@@ -618,7 +618,7 @@
 
 void must_have_n_keys(const char *filename, const char *option, const struct key2 *key2, int n);
 
-int ascii2keydirection(int msglevel, const char *str);
+int ascii2keydirection(msglvl_t msglevel, const char *str);
 
 const char *keydirection2ascii(int kd, bool remote, bool humanreadable);
 
src/openvpn/dco.c +4 -4
index 70a8c0a..881459c 100644
@@ -233,7 +233,7 @@
 }
 
 static bool
-dco_check_option_ce(const struct connection_entry *ce, int msglevel, int mode)
+dco_check_option_ce(const struct connection_entry *ce, msglvl_t msglevel, int mode)
 {
     if (ce->fragment)
     {
@@ -293,7 +293,7 @@
 }
 
 bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(msglvl_t msglevel, const struct options *o)
 {
     /* check if no dev name was specified at all. In the case,
      * later logic will most likely stop OpenVPN, so no need to
@@ -430,7 +430,7 @@
 }
 
 bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(msglvl_t msglevel, const struct options *o)
 {
     /* At this point the ciphers have already been normalised */
     if (o->enable_ncp_fallback
@@ -480,7 +480,7 @@
 }
 
 bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(msglvl_t msglevel, const struct options *o)
 {
     if (!o->use_peer_id)
     {
src/openvpn/dco.h +8 -8
index 59acb18..a362977 100644
@@ -55,7 +55,7 @@
  * @param msglevel      level to print messages to
  * @return              true if ovpn-dco is available, false otherwise
  */
-bool dco_available(int msglevel);
+bool dco_available(msglvl_t msglevel);
 
 
 /**
@@ -75,7 +75,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_option(int msglevel, const struct options *o);
+bool dco_check_option(msglvl_t msglevel, const struct options *o);
 
 /**
  * Check whether the options struct has any further option that is not supported
@@ -87,7 +87,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_startup_option(int msglevel, const struct options *o);
+bool dco_check_startup_option(msglvl_t msglevel, const struct options *o);
 
 /**
  * Check whether any of the options pushed by the server is not supported by
@@ -98,7 +98,7 @@
  * @param o         the options struct that hold the options
  * @return          true if no conflict was detected, false otherwise
  */
-bool dco_check_pull_options(int msglevel, const struct options *o);
+bool dco_check_pull_options(msglvl_t msglevel, const struct options *o);
 
 /**
  * Initialize the DCO context
@@ -261,7 +261,7 @@
 typedef void *dco_context_t;
 
 static inline bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     return false;
 }
@@ -273,19 +273,19 @@
 }
 
 static inline bool
-dco_check_option(int msglevel, const struct options *o)
+dco_check_option(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_startup_option(int msglevel, const struct options *o)
+dco_check_startup_option(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
 
 static inline bool
-dco_check_pull_options(int msglevel, const struct options *o)
+dco_check_pull_options(msglvl_t msglevel, const struct options *o)
 {
     return false;
 }
src/openvpn/dco_freebsd.c +1 -1
index 65303cd..d5ca277 100644
@@ -658,7 +658,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     struct if_clonereq ifcr;
     char *buf = NULL;
src/openvpn/dco_linux.c +2 -2
index 40674e7..d8357ca 100644
@@ -74,7 +74,7 @@
  * @return ID on success, negative error code on error
  */
 static int
-resolve_ovpn_netlink_id(int msglevel)
+resolve_ovpn_netlink_id(msglvl_t msglevel)
 {
     int ret;
     struct nl_sock *nl_sock = nl_socket_alloc();
@@ -1199,7 +1199,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0)
     {
src/openvpn/dco_win.c +1 -1
index 01ba017..2d08ed8 100644
@@ -599,7 +599,7 @@
 }
 
 bool
-dco_available(int msglevel)
+dco_available(msglvl_t msglevel)
 {
     /* try to open device by symbolic name */
     HANDLE h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
src/openvpn/dns.c +1 -1
index 5421004..efb888a 100644
@@ -200,7 +200,7 @@
 }
 
 bool
-dns_options_verify(int msglevel, const struct dns_options *o)
+dns_options_verify(msglvl_t msglevel, const struct dns_options *o)
 {
     const struct dns_server *server = o->servers ? o->servers : o->servers_prepull;
     while (server)
src/openvpn/dns.h +1 -1
index 6d97b40..6cd98f2 100644
@@ -166,7 +166,7 @@
  * @param   o           Pointer to the DNS options to validate
  * @return              True if no error was found
  */
-bool dns_options_verify(int msglevel, const struct dns_options *o);
+bool dns_options_verify(msglvl_t msglevel, const struct dns_options *o);
 
 /**
  * Makes a deep copy of the passed DNS options.
src/openvpn/env_set.c +1 -1
index 6c7df8e..2ae71ab 100644
@@ -209,7 +209,7 @@
 }
 
 void
-env_set_print(int msglevel, const struct env_set *es)
+env_set_print(msglvl_t msglevel, const struct env_set *es)
 {
     if (check_debug_level(msglevel))
     {
src/openvpn/env_set.h +1 -1
index 3973a4e..ddcfa14 100644
@@ -85,7 +85,7 @@
 
 const char *env_set_get(const struct env_set *es, const char *name);
 
-void env_set_print(int msglevel, const struct env_set *es);
+void env_set_print(msglvl_t msglevel, const struct env_set *es);
 
 /**
  * Write a struct env_set to a file. Each item on one line.
src/openvpn/error.c +15 -17
index 1b98235..58c2fd1 100644
@@ -48,12 +48,12 @@
 #endif
 
 /* Globals */
-unsigned int x_debug_level; /* GLOBAL */
+msglvl_t x_debug_level; /* GLOBAL */
 
 /* Mute state */
-static int mute_cutoff;   /* GLOBAL */
-static int mute_count;    /* GLOBAL */
-static int mute_category; /* GLOBAL */
+static int mute_cutoff;        /* GLOBAL */
+static int mute_count;         /* GLOBAL */
+static msglvl_t mute_category; /* GLOBAL */
 
 /*
  * Output mode priorities are as follows:
@@ -103,16 +103,14 @@
 bool
 set_debug_level(const int level, const unsigned int flags)
 {
-    const int ceiling = 15;
-
-    if (level >= 0 && level <= ceiling)
+    if (level >= 0 && level <= M_DEBUG_LEVEL)
     {
-        x_debug_level = level;
+        x_debug_level = (msglvl_t)level;
         return true;
     }
     else if (flags & SDL_CONSTRAIN)
     {
-        x_debug_level = constrain_int(level, 0, ceiling);
+        x_debug_level = (msglvl_t)constrain_int(level, 0, M_DEBUG_LEVEL);
         return true;
     }
     return false;
@@ -132,7 +130,7 @@
     }
 }
 
-int
+msglvl_t
 get_debug_level(void)
 {
     return x_debug_level;
@@ -190,7 +188,7 @@
  * Return a file to print messages to before syslog is opened.
  */
 FILE *
-msg_fp(const unsigned int flags)
+msg_fp(const msglvl_t flags)
 {
     FILE *fp = msgfp;
     if (!fp)
@@ -214,7 +212,7 @@
 int x_msg_line_num; /* GLOBAL */
 
 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const msglvl_t flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -235,7 +233,7 @@
 }
 
 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const msglvl_t flags, const char *format, va_list arglist)
 {
     struct gc_arena gc;
 #if SYSLOG_CAPABILITY
@@ -385,13 +383,13 @@
  * Apply muting filter.
  */
 bool
-dont_mute(unsigned int flags)
+dont_mute(msglvl_t flags)
 {
     bool ret = true;
     if (mute_cutoff > 0 && !(flags & M_NOMUTE))
     {
-        const int mute_level = DECODE_MUTE_LEVEL(flags);
-        if (mute_level > 0 && mute_level == mute_category)
+        const msglvl_t mute_level = DECODE_MUTE_LEVEL(flags);
+        if (mute_level == mute_category)
         {
             if (mute_count == mute_cutoff)
             {
@@ -750,7 +748,7 @@
  * Translate msg flags into a string
  */
 const char *
-msg_flags_string(const unsigned int flags, struct gc_arena *gc)
+msg_flags_string(const msglvl_t flags, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(16, gc);
     if (flags == M_INFO)
src/openvpn/error.h +27 -25

124 lines not on this page · raw message

src/openvpn/forward.c +3 -2
index 5d22fa3..12dd6a7 100644
@@ -368,7 +368,8 @@
 }
 
 bool
-send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel)
+send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                   msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     bool stat;
@@ -395,7 +396,7 @@
 }
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     if (c->c2.tls_multi)
     {
src/openvpn/forward.h +3 -2
index 79d0f8b..a575faf 100644
@@ -285,7 +285,7 @@
  * @param str        - The message to be sent
  * @param msglevel   - Message level to use for logging
  */
-bool send_control_channel_string(struct context *c, const char *str, int msglevel);
+bool send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel);
 
 /*
  * Send a string to remote over the TLS control channel.
@@ -303,7 +303,8 @@
  * @param msglevel   - Message level to use for logging
  */
 
-bool send_control_channel_string_dowork(struct tls_session *session, const char *str, int msglevel);
+bool send_control_channel_string_dowork(struct tls_session *session, const char *str,
+                                        msglvl_t msglevel);
 
 
 /**
src/openvpn/init.c +1 -1
index 2821cd4..0d7a2ec 100644
@@ -4273,7 +4273,7 @@
 }
 
 void
-management_show_net_callback(void *arg, const int msglevel)
+management_show_net_callback(void *arg, const msglvl_t msglevel)
 {
 #ifdef _WIN32
     show_routes(msglevel);
src/openvpn/init.h +1 -1
index a807874..e89615b 100644
@@ -136,7 +136,7 @@
 
 void close_management(void);
 
-void management_show_net_callback(void *arg, const int msglevel);
+void management_show_net_callback(void *arg, const msglvl_t msglevel);
 
 #endif
 
src/openvpn/manage.c +1 -1
index 4decdfe..c675e95 100644
@@ -1475,7 +1475,7 @@
         }
         else
         {
-            msg(M_CLIENT, "SUCCESS: verb=%d", get_debug_level());
+            msg(M_CLIENT, "SUCCESS: verb=%u", get_debug_level());
         }
     }
     else if (streq(p[0], "mute"))
src/openvpn/manage.h +1 -1
index 7c189ba..bff96d3 100644
@@ -176,7 +176,7 @@
     unsigned int flags;
 
     void (*status)(void *arg, const int version, struct status_output *so);
-    void (*show_net)(void *arg, const int msglevel);
+    void (*show_net)(void *arg, const msglvl_t msglevel);
     int (*kill_by_cn)(void *arg, const char *common_name);
     int (*kill_by_addr)(void *arg, const in_addr_t addr, const int port, const int proto);
     void (*delete_event)(void *arg, event_t event);
src/openvpn/mtu.c +2 -2
index a419e32..9c1a772 100644
@@ -187,7 +187,7 @@
 }
 
 void
-frame_print(const struct frame *frame, int level, const char *prefix)
+frame_print(const struct frame *frame, msglvl_t msglevel, const char *prefix)
 {
     struct gc_arena gc = gc_new();
     struct buffer out = alloc_buf_gc(256, &gc);
@@ -208,7 +208,7 @@
     buf_printf(&out, " ET:%d", frame->extra_tun);
     buf_printf(&out, " ]");
 
-    msg(level, "%s", out.data);
+    msg(msglevel, "%s", out.data);
     gc_free(&gc);
 }
 
src/openvpn/mtu.h +1 -1
index c092461..3bbff6f 100644
@@ -181,7 +181,7 @@
  * Function prototypes.
  */
 
-void frame_print(const struct frame *frame, int level, const char *prefix);
+void frame_print(const struct frame *frame, msglvl_t msglevel, const char *prefix);
 
 void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af);
 
src/openvpn/multi.c +1 -1
index 6e4cc42..8676a09 100644
@@ -3316,7 +3316,7 @@
     }
     else
     {
-        int msglevel = D_DCO;
+        msglvl_t msglevel = D_DCO;
         if (dco->dco_message_type == OVPN_CMD_DEL_PEER
             && dco->dco_del_peer_reason == OVPN_DEL_PEER_REASON_USERSPACE)
         {
src/openvpn/options.c +52 -48

330 lines not on this page · raw message

src/openvpn/options.h +6 -6
index bb2c052..a737711 100644
@@ -822,7 +822,7 @@
     struct pull_filter *tail;
 };
 
-void parse_argv(struct options *options, const int argc, char *argv[], const int msglevel,
+void parse_argv(struct options *options, const int argc, char *argv[], const msglvl_t msglevel,
                 const unsigned int permission_mask, unsigned int *option_types_found,
                 struct env_set *es);
 
@@ -888,7 +888,7 @@
 
 void options_detach(struct options *o);
 
-void options_server_import(struct options *o, const char *filename, int msglevel,
+void options_server_import(struct options *o, const char *filename, msglvl_t msglevel,
                            unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
@@ -897,13 +897,13 @@
 void rol_check_alloc(struct options *options);
 
 int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num,
-               int msglevel, struct gc_arena *gc);
+               msglvl_t msglevel, struct gc_arena *gc);
 
 /*
  * parse/print topology coding
  */
 
-int parse_topology(const char *str, const int msglevel);
+int parse_topology(const char *str, const msglvl_t msglevel);
 
 const char *print_topology(const int topology);
 
@@ -917,11 +917,11 @@
 
 int auth_retry_get(void);
 
-bool auth_retry_set(const int msglevel, const char *option);
+bool auth_retry_set(const msglvl_t msglevel, const char *option);
 
 const char *auth_retry_print(void);
 
-void options_string_import(struct options *options, const char *config, const int msglevel,
+void options_string_import(struct options *options, const char *config, const msglvl_t msglevel,
                            const unsigned int permission_mask, unsigned int *option_types_found,
                            struct env_set *es);
 
src/openvpn/options_util.c +4 -4
index 5740ee5..cb4229e 100644
@@ -117,7 +117,7 @@
 }
 
 int
-positive_atoi(const char *str, int msglevel)
+positive_atoi(const char *str, msglvl_t msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -132,7 +132,7 @@
 }
 
 bool
-positive_atoll(const char *str, int64_t *value, const char *name, int msglevel)
+positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel)
 {
     char *endptr;
     long long ll = strtoll(str, &endptr, 10);
@@ -148,7 +148,7 @@
 }
 
 int
-atoi_warn(const char *str, int msglevel)
+atoi_warn(const char *str, msglvl_t msglevel)
 {
     char *endptr;
     long long i = strtoll(str, &endptr, 10);
@@ -163,7 +163,7 @@
 }
 
 bool
-atoi_constrained(const char *str, int *value, const char *name, int min, int max, int msglevel)
+atoi_constrained(const char *str, int *value, const char *name, int min, int max, msglvl_t msglevel)
 {
     ASSERT(min < max);
 
src/openvpn/options_util.h +4 -4
index 45417d9..1492eef 100644
@@ -37,7 +37,7 @@
  * Converts a str to a positive number if the string represents a postive
  * integer number. Otherwise print a warning with msglevel and return 0
  */
-int positive_atoi(const char *str, int msglevel);
+int positive_atoi(const char *str, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -48,13 +48,13 @@
  *
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
-bool positive_atoll(const char *str, int64_t *value, const char *name, int msglevel);
+bool positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
  * integer number. Otherwise print a warning with \p msglevel and return 0
  */
-int atoi_warn(const char *str, int msglevel);
+int atoi_warn(const char *str, msglvl_t msglevel);
 
 /**
  * Converts a str to an integer if the string can be represented as an
@@ -66,7 +66,7 @@
  * @return \c true if the integer has been parsed and stored in value, \c false otherwise
  */
 bool atoi_constrained(const char *str, int *value, const char *name, int min, int max,
-                      int msglevel);
+                      msglvl_t msglevel);
 
 /**
  * Filter an option line by all pull filters.
src/openvpn/packet_id.c +5 -4
index 09696db..ca318eb 100644
@@ -53,15 +53,15 @@
 #define SEQ_EXPIRED ((time_t)1)
 
 #ifdef ENABLE_DEBUG
-static void packet_id_debug_print(int msglevel, const struct packet_id_rec *p,
+static void packet_id_debug_print(msglvl_t msglevel, const struct packet_id_rec *p,
                                   const struct packet_id_net *pin, const char *message,
                                   packet_id_print_type value);
 
 #endif /* ENABLE_DEBUG */
 
 static inline void
-packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
-                const char *message, uint64_t value)
+packet_id_debug(msglvl_t msglevel, const struct packet_id_rec *p,
+                const struct packet_id_net *pin, const char *message, uint64_t value)
 {
 #ifdef ENABLE_DEBUG
     if (unlikely(check_debug_level(msglevel)))
@@ -573,7 +573,8 @@
 #ifdef ENABLE_DEBUG
 
 static void
-packet_id_debug_print(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin,
+packet_id_debug_print(msglvl_t msglevel, const struct packet_id_rec *p,
+                      const struct packet_id_net *pin,
                       const char *message, packet_id_print_type value)
 {
     struct gc_arena gc = gc_new();
src/openvpn/pkcs11.c +3 -3
index dfc87f6..8a7a320 100644
@@ -72,10 +72,10 @@
 #endif
 };
 
-static unsigned
+static msglvl_t
 _pkcs11_msg_pkcs112openvpn(const unsigned flags)
 {
-    unsigned openvpn_flags;
+    msglvl_t openvpn_flags;
 
     switch (flags)
     {
@@ -112,7 +112,7 @@
 }
 
 static unsigned
-_pkcs11_msg_openvpn2pkcs11(const unsigned flags)
+_pkcs11_msg_openvpn2pkcs11(const msglvl_t flags)
 {
     unsigned pkcs11_flags;
 
src/openvpn/plugin.c +4 -4
index ea76a08..a105058 100644
@@ -50,7 +50,7 @@
 static struct plugin_common *static_plugin_common = NULL; /* GLOBAL */
 
 static void
-plugin_show_string_array(int msglevel, const char *name, const char *array[])
+plugin_show_string_array(msglvl_t msglevel, const char *name, const char *array[])
 {
     int i;
     for (i = 0; array[i]; ++i)
@@ -63,7 +63,7 @@
 }
 
 static void
-plugin_show_args_env(int msglevel, const char *argv[], const char *envp[])
+plugin_show_args_env(msglvl_t msglevel, const char *argv[], const char *envp[])
 {
     if (check_debug_level(msglevel))
     {
@@ -184,7 +184,7 @@
 
 #ifndef ENABLE_SMALL
 void
-plugin_option_list_print(const struct plugin_option_list *list, int msglevel)
+plugin_option_list_print(const struct plugin_option_list *list, msglvl_t msglevel)
 {
     int i;
     struct gc_arena gc = gc_new();
@@ -995,7 +995,7 @@
 
 #ifdef ENABLE_DEBUG
 void
-plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr)
+plugin_return_print(const msglvl_t msglevel, const char *prefix, const struct plugin_return *pr)
 {
     int i;
     msg(msglevel, "PLUGIN_RETURN_PRINT %s", prefix);
src/openvpn/plugin.h +2 -2
index 63999b6..81d3739 100644
@@ -111,7 +111,7 @@
 bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc);
 
 #ifndef ENABLE_SMALL
-void plugin_option_list_print(const struct plugin_option_list *list, int msglevel);
+void plugin_option_list_print(const struct plugin_option_list *list, msglvl_t msglevel);
 
 #endif
 
@@ -136,7 +136,7 @@
 void plugin_return_free(struct plugin_return *pr);
 
 #ifdef ENABLE_DEBUG
-void plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr);
+void plugin_return_print(const msglvl_t msglevel, const char *prefix, const struct plugin_return *pr);
 
 #endif
 
src/openvpn/pool.c +1 -1
index fde6cea..28ddd2c 100644
@@ -114,7 +114,7 @@
  * Verify start/end range
  */
 bool
-ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end)
+ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end)
 {
     struct gc_arena gc = gc_new();
     bool ret = true;
src/openvpn/pool.h +1 -1
index 6cecef0..36e9fca 100644
@@ -78,7 +78,7 @@
 
 void ifconfig_pool_free(struct ifconfig_pool *pool);
 
-bool ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_addr_t end);
+bool ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end);
 
 ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local,
                                            in_addr_t *remote, struct in6_addr *remote_ipv6,
src/openvpn/proto.c +1 -1
index 34b3378..ab77887 100644
@@ -183,7 +183,7 @@
             int hlen;
             int totlen;
             const char *msgstr = "PACKET SIZE INFO";
-            unsigned int msglevel = D_PACKET_TRUNC_DEBUG;
+            msglvl_t msglevel = D_PACKET_TRUNC_DEBUG;
 
             if (BLEN(&buf) < (int)sizeof(struct openvpn_iphdr))
             {
src/openvpn/push.c +7 -7
index 1ea7ed9..60ca25f 100644
@@ -373,8 +373,8 @@
  *
  * @return true on success, false on failure.
  */
-static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel,
-                            const char *fmt, ...)
+static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                            msglvl_t msglevel, const char *fmt, ...)
 #ifdef __GNUC__
 #if __USE_MINGW_ANSI_STDIO
     __attribute__((format(gnu_printf, 4, 5)))
@@ -853,7 +853,7 @@
 
 static void
 push_option_ex(struct gc_arena *gc, struct push_list *push_list, const char *opt, bool enable,
-               int msglevel)
+               msglvl_t msglevel)
 {
     if (!string_class(opt, CC_ANY, CC_COMMA))
     {
@@ -881,7 +881,7 @@
 }
 
 void
-push_option(struct options *o, const char *opt, int msglevel)
+push_option(struct options *o, const char *opt, msglvl_t msglevel)
 {
     push_option_ex(&o->gc, &o->push_list, opt, true, msglevel);
 }
@@ -902,7 +902,7 @@
 }
 
 void
-push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc)
+push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc)
 {
     const char **argv = make_extended_arg_array(p, false, gc);
     char *opt = print_argv(argv, gc, 0);
@@ -910,8 +910,8 @@
 }
 
 static bool
-push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msglevel, const char *format,
-                ...)
+push_option_fmt(struct gc_arena *gc, struct push_list *push_list,
+                msglvl_t msglevel, const char *format, ...)
 {
     va_list arglist;
     char tmp[256] = { 0 };
src/openvpn/push.h +2 -2
index 8ffd0c2..6b3275e 100644
@@ -99,9 +99,9 @@
 
 void clone_push_list(struct options *o);
 
-void push_option(struct options *o, const char *opt, int msglevel);
+void push_option(struct options *o, const char *opt, msglvl_t msglevel);
 
-void push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc);
+void push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc);
 
 void push_reset(struct options *o);
 
src/openvpn/route.c +13 -13
index e504485..aa5ce69 100644
@@ -1228,28 +1228,28 @@
 }
 
 static void
-print_route_option(const struct route_option *ro, int level)
+print_route_option(const struct route_option *ro, msglvl_t msglevel)
 {
-    msg(level, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
+    msg(msglevel, "  route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->netmask),
         show_opt(ro->gateway), show_opt(ro->metric));
 }
 
 void
-print_route_options(const struct route_option_list *rol, int level)
+print_route_options(const struct route_option_list *rol, msglvl_t msglevel)
 {
     struct route_option *ro;
     if (rol->flags & RG_ENABLE)
     {
-        msg(level, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
+        msg(msglevel, "  [redirect_default_gateway local=%d]", (rol->flags & RG_LOCAL) != 0);
     }
     for (ro = rol->routes; ro; ro = ro->next)
     {
-        print_route_option(ro, level);
+        print_route_option(ro, msglevel);
     }
 }
 
 void
-print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi,
                       const struct route_ipv6_gateway_info *rgi6)
 {
     struct gc_arena gc = gc_new();
@@ -1323,23 +1323,23 @@
 #endif /* ifndef ENABLE_SMALL */
 
 static void
-print_route(const struct route_ipv4 *r, int level)
+print_route(const struct route_ipv4 *r, msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
     if (r->flags & RT_DEFINED)
     {
-        msg(level, "%s", route_string(r, &gc));
+        msg(msglevel, "%s", route_string(r, &gc));
     }
     gc_free(&gc);
 }
 
 void
-print_routes(const struct route_list *rl, int level)
+print_routes(const struct route_list *rl, msglvl_t msglevel)
 {
     struct route_ipv4 *r;
     for (r = rl->routes; r; r = r->next)
     {
-        print_route(r, level);
+        print_route(r, msglevel);
     }
 }
 
@@ -3059,18 +3059,18 @@
  * Show current routing table
  */
 void
-show_routes(int msglev)
+show_routes(msglvl_t msglevel)
 {
     struct gc_arena gc = gc_new();
 
     const MIB_IPFORWARDTABLE *rt = get_windows_routing_table(&gc);
 
-    msg(msglev, "SYSTEM ROUTING TABLE");
+    msg(msglevel, "SYSTEM ROUTING TABLE");
     if (rt)
     {
         for (DWORD i = 0; i < rt->dwNumEntries; ++i)
         {
-            msg(msglev, "%s", format_route_entry(&rt->table[i], &gc));
+            msg(msglevel, "%s", format_route_entry(&rt->table[i], &gc));
         }
     }
     gc_free(&gc);
src/openvpn/route.h +4 -4
index 9b6a47e..c5006ae 100644
@@ -356,7 +356,7 @@
 void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi, const struct in6_addr *dest,
                               openvpn_net_ctx_t *ctx);
 
-void print_default_gateway(const int msglevel, const struct route_gateway_info *rgi,
+void print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi,
                            const struct route_ipv6_gateway_info *rgi6);
 
 /*
@@ -371,15 +371,15 @@
 int test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi);
 
 #ifndef ENABLE_SMALL
-void print_route_options(const struct route_option_list *rol, int level);
+void print_route_options(const struct route_option_list *rol, msglvl_t msglevel);
 
 #endif
 
-void print_routes(const struct route_list *rl, int level);
+void print_routes(const struct route_list *rl, msglvl_t msglevel);
 
 #ifdef _WIN32
 
-void show_routes(int msglev);
+void show_routes(msglvl_t msglevel);
 
 bool test_routes(const struct route_list *rl, const struct tuntap *tt);
 
src/openvpn/run_command.c +1 -1
index 4a1ef22..a0c9484 100644
@@ -107,7 +107,7 @@
 
 #ifndef WIN32
 bool
-openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel)
+openvpn_waitpid_check(pid_t pid, const char *msg_prefix, msglvl_t msglevel)
 {
     if (pid == 0)
     {
src/openvpn/run_command.h +5 -5
index afd1b88..234055e 100644
@@ -71,13 +71,13 @@
  * This function is currently not implemented for Windows as the helper
  * macros used by this function are not available.
  *
- * @param pid               pid of the process to be checked
+ * @param pid            pid of the process to be checked
  * @param msg_prefix     prefixed of the message that be printed
- * @param msglevel          msglevel of the messages to be printed
- * @return                  true if the process is still running, false if
- *                          an error condition occurred
+ * @param msglevel       msglevel of the messages to be printed
+ * @return               true if the process is still running, false if
+ *                       an error condition occurred
  */
-bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel);
+bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, msglvl_t msglevel);
 
 #endif
 
src/openvpn/sig.c +1 -1
index ecea635..42ad823 100644
@@ -287,7 +287,7 @@
 }
 
 void
-print_signal(const struct signal_info *si, const char *title, int msglevel)
+print_signal(const struct signal_info *si, const char *title, msglvl_t msglevel)
 {
     if (si)
     {
src/openvpn/sig.h +1 -1
index 7e5dd9f..b5d81fc 100644
@@ -66,7 +66,7 @@
 
 void restore_signal_state(void);
 
-void print_signal(const struct signal_info *si, const char *title, int msglevel);
+void print_signal(const struct signal_info *si, const char *title, msglvl_t msglevel);
 
 void print_status(struct context *c, struct status_output *so);
 
src/openvpn/socket.c +4 -3
index 306170c..eeb42d1 100644
@@ -78,7 +78,7 @@
 static int
 get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname, void *network,
                  unsigned int *netbits, int resolve_retry_seconds, struct signal_info *sig_info,
-                 int msglevel)
+                 msglvl_t msglevel)
 {
     char *endp, *sep, *var_host = NULL;
     struct addrinfo *ai = NULL;
@@ -211,7 +211,8 @@
 }
 
 bool
-get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
+get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
+              msglvl_t msglevel)
 {
     if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostname, network, netbits, 0, NULL, msglevel)
         < 0)
@@ -1516,7 +1517,7 @@
 linksock_print_addr(struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
-    const int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
+    const msglvl_t msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
 
     /* print local address */
     if (sock->bind_local)
src/openvpn/socket_util.c +3 -3
index 9b7312d..fa566e7 100644
@@ -541,7 +541,7 @@
     struct addrinfo hints;
     int status;
     struct signal_info sigrec = { 0 };
-    int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
+    msglvl_t msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
     struct gc_arena gc = gc_new();
     const char *print_hostname;
     const char *print_servname;
@@ -604,7 +604,7 @@
         int resolve_retries =
             (flags & GETADDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) / fail_wait_interval);
         const char *fmt;
-        int level = 0;
+        msglvl_t level = 0;
 
         /* this is not a numeric IP, therefore force resolution using the
          * provided ai_family */
@@ -739,7 +739,7 @@
 done:
     if (sig_info && sig_info->signal_received)
     {
-        int level = 0;
+        msglvl_t level = 0;
         if (flags & GETADDR_FATAL_ON_SIGNAL)
         {
             level = M_FATAL;
src/openvpn/socket_util.h +1 -1
index 361edff..ada52a4 100644
@@ -142,7 +142,7 @@
  * Translate an IPv6 addr or hostname from string form to in6_addr
  */
 bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
-                   int msglevel);
+                   msglvl_t msglevel);
 
 int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname,
                         int resolve_retry_seconds, struct signal_info *sig_info, int ai_family,
src/openvpn/ssl_verify_backend.h +2 -2
index a0559c9..2bad3eb 100644
@@ -193,8 +193,8 @@
  * @param gc            Garbage collection arena for temp data
  *
  */
-void x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
-                    struct gc_arena *gc);
+void x509_track_add(const struct x509_track **ll_head, const char *name,
+                    msglvl_t msglevel, struct gc_arena *gc);
 
 /*
  * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_mbedtls.c +1 -1
index cfcfb25..3588071 100644
@@ -350,7 +350,7 @@
 }
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, msglvl_t msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/ssl_verify_openssl.c +1 -1
index 6de7e2a..0f257e2 100644
@@ -414,7 +414,7 @@
  */
 
 void
-x509_track_add(const struct x509_track **ll_head, const char *name, int msglevel,
+x509_track_add(const struct x509_track **ll_head, const char *name, msglvl_t msglevel,
                struct gc_arena *gc)
 {
     struct x509_track *xt;
src/openvpn/status.c +2 -3
index 34e5a2f..cea31f5 100644
@@ -230,14 +230,13 @@
 
         if (so->msglevel >= 0 && !so->errors)
         {
-            msg(so->msglevel, "%s", buf);
+            msg((msglvl_t)so->msglevel, "%s", buf);
         }
 
         if (so->fd >= 0 && !so->errors)
         {
-            int len;
             strcat(buf, "\n");
-            len = strlen(buf);
+            size_t len = strlen(buf);
             if (len > 0)
             {
                 if (write(so->fd, buf, len) != len)
src/openvpn/status.h +1 -0
index 0c7a869..25e1663 100644
@@ -53,6 +53,7 @@
 
     char *filename;
     int fd;
+    /* NB: -1 is used to indicate that output should only go to the file */
     int msglevel;
     const struct virtual_output *vout;
 
src/openvpn/tun.c +27 -27

146 lines not on this page · raw message

src/openvpn/tun.h +2 -2
index 06fc729..6562c22 100644
@@ -445,9 +445,9 @@
 DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count,
                           in_addr_t *netmask);
 
-void show_tap_win_adapters(int msglev, int warnlev);
+void show_tap_win_adapters(msglvl_t msglevel, msglvl_t warnlevel);
 
-void show_adapters(int msglev);
+void show_adapters(msglvl_t msglevel);
 
 void tap_allow_nonadmin_access(const char *dev_node);
 
tests/unit_tests/openvpn/mock_msg.c +9 -9
index 603520b..69d2d1d 100644
@@ -38,8 +38,8 @@
 #include "error.h"
 #include "mock_msg.h"
 
-unsigned int x_debug_level = 0; /* Default to (almost) no debugging output */
-unsigned int print_x_debug_level = 0;
+msglvl_t x_debug_level = 0; /* Default to (almost) no debugging output */
+msglvl_t print_x_debug_level = 0;
 
 bool fatal_error_triggered = false;
 
@@ -47,31 +47,31 @@
 
 
 void
-mock_set_debug_level(int level)
+mock_set_debug_level(msglvl_t level)
 {
     x_debug_level = level;
 }
 
-int
+msglvl_t
 mock_get_debug_level(void)
 {
     return x_debug_level;
 }
 
 void
-mock_set_print_debug_level(int level)
+mock_set_print_debug_level(msglvl_t level)
 {
     print_x_debug_level = level;
 }
 
-int
+msglvl_t
 get_debug_level(void)
 {
     return x_debug_level;
 }
 
 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const msglvl_t flags, const char *format, va_list arglist)
 {
     if (flags & M_FATAL)
     {
@@ -89,7 +89,7 @@
 }
 
 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const msglvl_t flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -128,7 +128,7 @@
 }
 
 bool
-dont_mute(unsigned int flags)
+dont_mute(msglvl_t flags)
 {
     return true;
 }
tests/unit_tests/openvpn/mock_msg.h +3 -5
index f4ebc23..6dddf0b 100644
@@ -28,17 +28,15 @@
  * this function from your test driver to increase debug output when you
  * need debug output.
  */
-void mock_set_debug_level(int level);
+void mock_set_debug_level(msglvl_t level);
 
 #define MOCK_MSG_BUF 2048
 
 extern bool fatal_error_triggered;
 extern char mock_msg_buf[MOCK_MSG_BUF];
 
-void mock_set_debug_level(int level);
+msglvl_t mock_get_debug_level(void);
 
-int mock_get_debug_level(void);
-
-void mock_set_print_debug_level(int level);
+void mock_set_print_debug_level(msglvl_t level);
 
 #endif /* MOCK_MSG */
tests/unit_tests/openvpn/mock_ssl_dependencies.c +1 -1
index 7333c47..f2fa93a 100644
@@ -38,7 +38,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_argv.c +1 -1
index a65857b..a04fabc 100644
@@ -23,7 +23,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  msglvl_t msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_misc.c +2 -2
index 93e2460..dbfdd56 100644
@@ -339,8 +339,8 @@
     assert_false(valid_integer("-2147483653", false));
 
 
-    int msglevel = D_LOW;
-    int saved_log_level = mock_get_debug_level();
+    msglvl_t msglevel = D_LOW;
+    msglvl_t saved_log_level = mock_get_debug_level();
     mock_set_debug_level(D_LOW);
 
     /* check happy path */
tests/unit_tests/openvpn/test_pkcs11.c +1 -1
index 9ba6cfc..d568865 100644
@@ -59,7 +59,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_pkt.c +1 -1
index 5122766..b6c612b 100644
@@ -45,7 +45,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     /* Dummy function to get the linker happy, should never be called */
     assert_true(false);
tests/unit_tests/openvpn/test_push_update_msg.c +2 -2
index 87329b1..8a5beeb 100644
@@ -111,7 +111,7 @@
 
 #ifndef ENABLE_MANAGEMENT
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     return true;
 }
@@ -120,7 +120,7 @@
 int i;
 
 bool
-send_control_channel_string(struct context *c, const char *str, int msglevel)
+send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
 {
     if (res && res[i] && strcmp(res[i], str))
     {
tests/unit_tests/openvpn/test_socket.c +1 -1
index 2da2529..7f740ac 100644
@@ -59,7 +59,7 @@
 
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;
tests/unit_tests/openvpn/test_tls_crypt.c +1 -1
index 532bfcd..44d51fe 100644
@@ -98,7 +98,7 @@
 
 int
 __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-                  int msglevel, struct gc_arena *gc)
+                  msglvl_t msglevel, struct gc_arena *gc)
 {
     p[0] = PATH1 PATH2;
     p[1] = PARAM1;
tests/unit_tests/openvpn/test_user_pass.c +1 -1
index 460b37f..32ec59f 100644
@@ -73,7 +73,7 @@
 /* stubs for some unused functions instead of pulling in too many dependencies */
 int
 parse_line(const char *line, char **p, const int n, const char *file, const int line_num,
-           int msglevel, struct gc_arena *gc)
+           msglvl_t msglevel, struct gc_arena *gc)
 {
     assert_true(0);
     return 0;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1110?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id492cb774c6d022d06bb3cf5fec2a4bdd410e619
Gerrit-Change-Number: 1110
Gerrit-PatchSet: 17
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset